MATLAB 2D Plot command
The basic plot function in MATLAB is the plot linear plot command. The simple plot command takes two vectors X and Y and plots them in 2D space.
The plot command can plot in color and with different symbols.
Let’s issue the plot command from the Command Window prompt. Create two vectors for the plot command.
>> x = linspace(-pi,pi,100); >> y = tan(sin(x)) - sin(tan(x)); >> plot(x,y)
linspace creates a linearly spaced vector. For example,
linspace(low,high,N) created N points between low and high.
Lets write a simple script to add title , labels to the graph.
% Sample MATLAB Script to plot a function % MATLAB Tutorials - www.TestingDocs.com x = linspace(-pi,pi,100); % 100 linearly spaced points within [-pi,pi] y = tan(sin(x)) - sin(tan(x)); % Plot function plot(x,y); xlabel('x-axis'); ylabel('y-axis'); title('MATLAB 2D Plot Demo - www.TestingDocs.com');
Run the script.
Notice that the graph now has a title and x,y axis labels.
Adding markers to the plot command.
MATLAB Tutorials on this website can be found here:
To try MATLAB Software or to learn more about MATLAB,
MATLAB official website: