6.2. Two-Dimensional Plots
To draw a 2-D plot in MATLAB, the plot command is used. The syntax is given as follows:
plot(x, y)
where
x is a vector containing the x-coordinates of the plot and
y is a vector containing the y-coordinates of the plot.
When executed, the command will create a plot in the MATLAB figure window with data in vector x taken along x-axis and data in vector y along y-axis.
In case figure window already exits, it clears the current figure window and draws a new plot.
Example 6.1.
Plot the curve given by equation y = x2 where x varies from 0 to 10. Solution: The program to plot the curve given by equation y = x2 is given as follows: x = 0 : 1 : 10; %Statement 1 y = x .^ 2; %Statement 2 plot(x, y); %Statement 3 Statement ... |
Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.