MATLAB AND PLOTS - PYTHON

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

GROUP MEMBERS :

1. Riya Kanojia – 25
2. Vaishnavi Kadam - 24
3. Shruti Rai - 44
4. Shreya Shinde - 53
5. Sejal Shukla – 54
6. Haneef Shaikh - 50

MATLAB AND PLOT

INTRODUCTION :

Like other well-known programming languages like Java, C#, etc., MATLAB has its own Integrated
Development Environment (IDE) and collection of libraries. Since it was initially known as the matrix
programming language, MATLAB is an acronym for "Matrix Laboratory." It is a programming
language of the fourth generation. It is a multi-paradigm, MATLAB. Therefore, it can be used with a
variety of programming paradigms, including functional, Visual, and Object-Oriented.

Cleve Moler, the department head of computer science at the University of New Mexico at the time,
made the initial discovery. He wanted to develop a different approach for his students to do linear
algebra and numerical computations without needing to utilize Fortran. Cleve Molar, Steve Bangart,
and Jack Little founded MathWorks in 1984 after seeing MATLAB's economic potential.

The plot function in MATLAB is used to create a graphical representation of some data. It is often
very easy to "see" a trend in data when plotted, and very difficult when just looking at the raw
numbers.

TYPES OF MATLAB :

Some important types of MATLAB’s are as follows:

 Data Types: MATLAB supports various data types, including numeric arrays, characters and
strings, tables, structures, cell arrays, function handles, dictionaries, and time series data.

 Numeric Arrays: MATLAB supports single-precision and double-precision floating-point


numbers, as well as integer data types, including int8, uint8, int16, uint16, int32, uint32,
int64, and uint64.

 Characters and Strings: MATLAB supports character arrays and string arrays, which can be
used to store text data.

 Tables: Tables are arrays in tabular form whose named columns can have different types.
They are useful for representing data in a tabular format, such as data from a spreadsheet or
database.

 Structures: Structures are arrays with named fields that can contain data of varying types and
sizes. They are useful for representing complex data structures.
 Cell Arrays: Cell arrays can contain data of varying types and sizes. They are useful for
storing mixed-type data in a single array.

 Function Handles: Function handles allow invoking a function indirectly. They are useful
for passing functions as arguments to other functions.

 Dictionaries: Dictionaries map data with keys that index values. They are useful for
representing data in a key-value format.

 Time Series Data: Time series data are vectors sampled over time. MATLAB provides
functions for manipulating and analyzing time series data.

 Data Type Identification and Conversion: Functions like class, who’s, is*, and valid ate
attributes help determine the data type of a variable or whether a variable has a specific data
type. Data type conversion functions like single, double, int8, uint8, int16, uint16, int32,
uint32, int64, uint64, string, char, datetime, duration, and categorical convert between
numeric arrays, strings and character arrays, dates and times, cell arrays, structures, or tables.

 Plots: MATLAB supports various types of plots, including line plots, scatter plots,
histograms, bar charts, geographic plots, polar plots, contour plots, vector field plots, surface
and mesh plots, volume visualization, animation, images, and more. These plot types help
visualize and analyze data in different ways, making it easier to understand and interpret the
results.

TYPES OF PLOT :
There are various types of plots in literature, each with its unique structure and characteristics. Here
are some common types of plots:

 Linear plot: This plot type presents events in a chronological order, starting from the
exposition, rising action, climax, falling action, and resolution. It is the most common plot
type used in short stories.

 Episodic plot: This plot type also employs a chronological structure, but it consists of a series
of events or more than one plot. It is found in long fiction, i.e. novels.

 Parallel plot: This plot type includes a series of events or more than one plot that share a
similar theme. It is found in long fiction, i.e. novels.

 Flashback plot: This plot type begins its story from any event in the story, so a writer may
choose to begin from the last scene or the climax, and then move their way back from there. It
is used in both short stories and novels.

 Quest plot: This plot type involves a protagonist who is forced to go on a dangerous quest to
achieve a goal. The protagonist faces various challenges and obstacles along the way, but
ultimately achieves their goal.

 Overcoming the monster plot: This plot type involves a protagonist who must confront and
defeat a powerful antagonist or monster. The protagonist must use their skills and wit to
overcome the antagonist and save the day.

 Rags to riches plot: This plot type involves a protagonist who starts off poor and unknown
but eventually becomes rich and famous. The protagonist faces various challenges and
obstacles along the way, but ultimately achieves their goal.
 Voyage and return plot: This plot type involves a protagonist who embarks on a journey to a
foreign land and faces various challenges and obstacles along the way. The protagonist
eventually returns home, but they are changed by their experiences.

 Comedy plot: This plot type involves a series of humorous events that ultimately lead to a
happy ending. The protagonist faces various challenges and obstacles along the way, but
ultimately achieves their goal.

 Tragedy plot: This plot type involves a protagonist who has a major character flaw or makes
a grave mistake that ultimately leads to their downfall. The protagonist's unfortunate end
evokes pity at their folly and the fall of a fundamentally good character.

USES OF PLOT AND MATLAB :


MATLAB:

MATLAB (Matrix Laboratory) is a powerful numerical computing environment and programming


language widely used in various scientific, engineering, and mathematical domains. It excels in tasks
involving:

 Linear Algebra Operations: MATLAB efficiently handles matrices, vectors, and tensors,
making it ideal for solving systems of linear equations, performing eigenvalue
decompositions, and manipulating large datasets.

 Matrix-Based Calculations: Its core strength lies in matrix-oriented calculations, allowing


for streamlined vectorization of operations and efficient handling of complex mathematical
computations.

 Signal Processing and Control Systems: Signal processing, control system design and
analysis, and filter design are common applications due to MATLAB's built-in functions and
toolboxes for these areas.

 Data Analysis and Visualization: MATLAB provides robust tools for data analysis,
including statistical functions, filtering, and regression. It also offers a rich set of plotting
functions to create informative visualizations of your data (discussed in the next section).

 Algorithm Development and Prototyping: Rapid prototyping and development of


algorithms are facilitated by MATLAB's interactive nature, allowing you to test and refine
your code efficiently.

 Machine Learning and Deep Learning: With the rise of machine learning, MATLAB has
expanded its capabilities with toolboxes like Statistics and Machine Learning Toolbox
(formerly known as the Neural Network Toolbox) and Deep Learning Toolbox, enabling you
to build, train, and deploy machine learning models.

PLOT FUNCTION IN MATLAB:

The plot function is a fundamental tool in MATLAB for creating visual representations of data. It
generates various types of plots. Matplotlib is a fundamental Python library for creating static,
animated, and interactive visualizations. Its object-oriented API offers a versatile toolkit for crafting
various plot types.
 Line Plots: A Line plot can be defined as a graph that displays data as points or check marks
above a number line, showing the frequency of each value. Here, for instance, the line plot
shows the number of ribbons of each length. A line plot is often confused with a line graph.

 2D Line Plots: 2D Plots in MATLAB is a feature that enables a user to create the two-
dimensional graph for any dependent variable as a function of a depending variable. A plot
can present the data in continuous, discrete, surface or volume form.

 3D Line Plots: A 3D surface plot is a three-dimensional graph that is useful for investigating
desirable response values and operating conditions. A surface plot contains the following
elements: Predictors on the x- and y-axes. A continuous surface that represents the response
values on the z-axis.

 Scatter Plots: Scatter plots' primary uses are to observe and show relationships between two
numeric variables. The dots in a scatter plot not only report the values of individual data
points, but also patterns when the data are taken as a whole. Identification of correlational
relationships are common with scatter plots.

 Bar Plots: A bar plot or bar chart is a graph that represents the category of data with
rectangular bars with lengths and heights that is proportional to the values which they
represent. The bar plots can be plotted horizontally or vertically.

 Histogram Plots: A histogram is a chart that plots the distribution of a numeric variable's
values as a series of bars. Each bar typically covers a range of numeric values called a bin or
class; a bar's height indicates the frequency of data points with a value within the
corresponding bin.

SIMILARITIES TO MATLAB PLOTTING :

MATLAB's plotting functionality shares some similarities with Matplotlib:

 Function-Oriented Approach: Both libraries provide functions for creating plots (e.g., plot
in Matplotlib, plot in MATLAB).

 Customization Options: Extensive customization options allow you to tailor plots to your
needs (e.g., labels, colours, markers, line styles).

 Sub plotting: subplots method provides a way to plot multiple plots on a single figure. Given
the number of rows and columns, it returns a tuple (fig , ax ), giving a single figure fig with an
array of axes ax.

KEY DIFFERENCES :
While the general concepts align, there are some key differences to consider:

 Object-Oriented vs. Function-Oriented: Function-oriented techniques such as SA/SD


group functions together if, as a group, they constitute a higher-level function. On the other
hand, object-oriented techniques group functions together on the basis of the data they operate
on.

 API Syntax: The API file supports defining functions, handlers and user defined types.
Functions are similar to C functions. They can take input and output parameters, and can
return a result. A handler is a special function type that can be registered for call-backs.
ADVANTAGES AND DISADVANTAGES OF PLOT AND MATLAB :

MATLAB

MATLAB is a high-level programming language and software environment for mathematical


computations, data analysis, algorithm development, and modeling, particularly suited for linear
algebra, numerical analysis, and matrix operations. It provides a comprehensive set of built-in
functions, toolboxes, and a user-friendly development environment, making it an ideal choice for
engineering, scientific, and mathematical applications.

ADVANTAGES OF MATLAB:

 Ease of use: MATLAB offers a simple syntax and intuitive interface, making it easy to learn
and use, even for users without extensive programming experience.

 Built-in functions and toolbox: MATLAB provides a wide range of built-in functions and
toolboxes, enabling users to perform complex mathematical operations and simulations with
ease.

 High-performance computing: MATLAB is designed for high-performance computing,


making it suitable for large-scale simulations and data analysis tasks.

 Visualization capabilities: MATLAB offers extensive visualization capabilities, including


2D and 3D plotting, making it easy to present and interpret results.

DISADVANTAGES OF MATLAB:

 Cost: MATLAB is a commercial software, and its licensing fees can be prohibitive for some
users, especially those in academia or small businesses.

 Limited customization: While MATLAB offers a wide range of built-in functions and
toolboxes, users may find it challenging to customize the software to their specific needs.

 Performance: MATLAB's interpreted language can result in slower execution times


compared to compiled languages like C or Fortran, particularly for large-scale computations.

 Limited support for parallel computing: While MATLAB supports parallel computing to
some extent, it may not be as efficient or flexible as other tools designed specifically for
parallel computing.

PLOT

Plot is a versatile and widely used data visualization library in Python, providing a MATLAB-like
plotting interface for two-dimensional plots. It is designed to be easy to use and highly customizable,
making it a popular choice for scientific and engineering applications.

ADVANTAGES OF PLOT:

 Ease of use: Plot offers a simple and intuitive interface, making it easy to create high-quality
plots with minimal effort.
 Customization: Plot is highly customizable, allowing users to fine-tune various aspects of
their plots, such as colors, line styles, and axis labels.

 Integration with other libraries: Plot can be easily integrated with other Python libraries,
such as NumPy and SciPy, enabling users to perform complex data analysis and visualization
tasks.

 Performance: Plot is built on top of NumPy and SciPy, which offer high-performance
computing capabilities, making it suitable for large-scale data analysis and visualization tasks.

DISADVANTAGES OF PLOT:

 Limited support for three-dimensional plots: While Plot supports two-dimensional plots, it
may not be as suitable for three-dimensional plots, which may require other libraries, such as
Matplotlib.

 Limited support for real-time data visualization: Plot may not be as suitable for real-time
data visualization, which may require other libraries, such as Pygame or Matplotlib's
animation capabilities.

 Limited support for interactive data visualization: Plot may not offer the same level of
interactivity as other libraries, such as Bokeh or Plotly, which may be better suited for
creating interactive visualizations.

CONCLUSION :
MATLAB is used for scientific analysis and computation of different algorithms. It can easily do
complex mathematical calculations, create and plot graphs, data visualization, and make the lives of
scientists and IT professionals easy. You can learn more about what is MATLAB and the real-world
usage of its functions with consistency.

MULTIPLE CHOICE QUESTION :


1. Which data type is used for storing text data in MATLAB?
a. Numeric arrays
b. Characters and strings
c. Tables
d. Function handles

2. What is the purpose of tables in MATLAB?


a. Storing mixed-type data
b. Representing complex data structures
c. Organizing data in tabular form
d. Handling time series data

3. What is the significance of cell arrays in MATLAB?


a. Storing numbers
b. Handling text data
c. Storing mixed-type data
d. Representing data with named fields

4. What is the purpose of using single and double functions in MATLAB?


a. For handling text data
b. For converting between different numeric types
c. For representing complex data structures
d. For handling time series data

5. What feature of MATLAB is used to store mixed-type data?


a. Characters and strings
b. Structures
c. Cell arrays
d. Numeric arrays

6. What is the primary purpose of dictionaries in MATLAB?


a. Storing numbers
b. Handling text data
c. Mapping data with keys to index values
d. Representing data with named fields

7. What feature of MATLAB is used for handling sequences of data sampled over time?
a. Structures
b. Time series data
c. Tables
d. Cell arrays

8. Which issue is common for both MATLAB and Plot?


a. Limited support for parallel computing
b. High cost
c. Easy customization
d. Real-time data visualization support
e. Extensive integration with other libraries

9. What's a drawback of Plot compared to MATLAB?


a. Limited support for three-dimensional plots
b. High cost
c. Easy customization
d. Limited support for parallel computing
e. Extensive visualization options

10. What's a MATLAB-specific issue, not found in Plot?


a. Limited support for real-time data visualization
b. High cost
c. Limited integration with other libraries
d. Limited support for interactive data visualization
e. Limited support for three-dimensional plots

11. What is a disadvantage of Plot compared to MATLAB?


a. Limited support for 3D plots
b. High cost
c. Extensive built-in functions
d. User-friendly development environment

12. Which language is Plot a data visualization library for?


a. C++
b. Java
c. Python
d. R

13. What is a benefit of using Plot with other Python libraries?


a. Increased performance for data analysis
b. Access to real-time data visualization tools
c. Support for creating mobile applications
d. Broader range of web development functionalities

14. MATLAB is better suited for which scenario?


a. Simple data visualization with Python
b. Complex mathematical modeling with limited budget
c. Highly customizable plots with real-time updates
d. Quick creation of interactive web-based visualizations

15. What is a limitation of MATLAB compared to Plot?


a. More difficult to learn and use
b. Less customizable plotting options
c. Slower execution times for large datasets
d. Fewer built-in functions for data manipulation

16. Which library would be a better choice for creating a dynamic dashboard with real-time data
updates?
a. Plot
b. MATLAB
c. Bokeh
d. SciPy

17. When choosing between MATLAB and Plot, a major deciding factor would be:
a. User experience with Python programming
b. Budgetary constraints
c. Need for extensive 3D visualizations
d. All of the above

18. What function would you use to check if a variable is of type double-precision floating-point?
a. class
b. whos
c. isfloat
d. all of the above

19. Which data structure is most suitable for representing data with named fields that can hold
different data types?
a. table
b. structure
c. cell array
d. function handle

20. How would you create a time series object in MATLAB?


a. Using a specific function like timeseries() (not available in base MATLAB)
b. Assigning time values to one vector and corresponding data points to another vector
c. Both methods a) and b) are valid
d. There's no built-in way to create time series objects in MATLAB
ONE LINE QUESTIONS

1. What data types does MATLAB support?


2. How does MATLAB handle numeric data?
3. What's the role of characters and strings in MATLAB?
4. Why are tables useful in MATLAB?
5. When do we use structures in MATLAB?
6. What's the purpose of cell arrays?
7. How are dictionaries used in MATLAB?
8. What's special about MATLAB's time series data handling?
9. How does MATLAB convert between data types?
10. Which library is Plot built on top of for numerical computations?

SHORT NOTES

1. Define Bar chart and Histogram in Plot


2. what is 2D line Plot in Matlab.
3. Advantages of MATLAB for high-performance computing
4. Customization options in Plot for data visualization
5. Limitations of Plot for 3D plotting and interactivity
6. Applications of MATLAB in engineering and science
7. What is the default data type for numeric variables in MATLAB?
8. How does MATLAB support data analysis and visualization?
9. What's the role of characters and strings in MATLAB?
10. Define Tables and cell Arrays

LONG QUESTIONS

1. Explain the advantages and disadvantages of MATLAB.

2. How does MATLAB help us handle different kinds of information, like numbers, text, and
organized tables, and how can we use these tools effectively in our projects?

3. Implement a Python function that takes an array of students' grades and generates a histogram using
Matplotlib. The histogram should help visualize the distribution of grades (0-100) across 10 bins. Add
appropriate labels and a title to your plot.

4. Write a Python script to generate a pie chart that shows the market share of five different brands
using Matplotlib. Customize the pie chart by exploding the largest segment, adding percentage labels
inside the chart, and including a shadow for better visualization.

5. Develop a Python script to plot a 3D surface plot of a mathematical function, such as z = x² + y²,
using Matplotlib’s mpl_toolkits.mplot3d. Configure the viewing angle to ensure the 3D effect is
clearly visible and label the axes appropriately.

REFERENCES :
https://in.mathworks.com/help/matlab/data-types.html

https://in.mathworks.com/help/matlab/examples.html?category=pie-charts-bar-plots-and-
histograms&s_tid=CRUX_topnav

https://rachnachhabria.blogspot.com/2011/06/working-with-different-types-of-plots.html?m=1
https://www.studiobinder.com/blog/what-is-a-plot/

http://www.mathworks.com/help/matlab/ref/plot.html

http://www.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html

https://realpython.com/matlab-vs-python/https://www.theknowledgeacademy.com/blog/what-is-
matlab/
https://www.simplilearn.com/tutorials/matlab-tutorial/what-is-matlab-introduction-for-
beginners#:~:text=Since%20it%20was%20initially%20known,Visual%2C%20and%20Object
%2DOriented

https://www.analyticsvidhya.com/blog/2023/10/what-is-matlab-working-functions-and-applications/

You might also like