![plot matlab plot matlab](https://blogs.mathworks.com/images/loren/118/pubQualityGraphics_01.png)
Plot(,’k:’) % dotted line in black from (0,0) to (4,4) Execute the following M-file, carefully noting the results of each command:Ĭlear all % file available in M-files folder as file1.m The functions f(x) = x2 and f−1(x) = √ x are inverse functions for x ≥ 0 and hence their graphs must be reflections through the line y = x. After the > prompt enter lookfor complex.Įxample 2: By using hold on and hold off, you can plot several functions on the same axes using a number of plot commands. Suppose you were interested in commands involving the use of complex numbers. For example, to get help on many graphics related commands, click on Plotting and Data Visualization.Īnother help option is the lookfor facility.
#PLOT MATLAB CODE#
You notice that we found the three y-arrays in a single line of code and they were plotted in different colours. Here t is measured in seconds and y1, y2, 圓 are measured in cm. You will need three dots in the expression to generate the array y.Įxercise 2: Plot the graph of y = sin9x + sin10.5x + sin12x for −π ≤ x ≤ π using 601 points.Įxample 1: Suppose you want to plot the oscillations y1 = cost, y2 = cos3t and their sum 圓 = y1 + y2, for 0 ≤ t ≤ 4π, on the same axes. Similarly, the second array contains the y-coordinates.Įxercise 1: Plot the graph of y = xex/ x 2 − π 2 for −3 ≤ x ≤ 2 using a step-size of 0.02. Note: Students often get this wrong by forgetting that the first array always contains the x-coordinates, not the two coordinates of the first point.
![plot matlab plot matlab](https://i.ytimg.com/vi/Dmz7-JzMs-U/maxresdefault.jpg)
For example, to plot a straight line from the point (1,7) to the point (3,-5) you need the command plot(,). Please note that you only need two points to plot a single straight line. In general, most graphs can be satisfactorily plotted using arrays of, say, 101 to 201 points, although erratic or wildly fluctuating functions would require many more points. Ĭlearly this attempt is unacceptable because we have not used sufficient points! Change the 11 to 201 and execute the code again. Type in the following as an attempt to graph y = sinx for 0 ≤ x ≤ 2π. If a Figure window already exists, another plot command clears the current Figure window by default (unless instructed not to do so) and draws a new plot. , (x(n), y(n)), and then graphs the data by connecting the points with straight lines. If x =, then the MATLAB command plot(x,y) opens a graphics window, called a Figure window, scales the axes to fit the data, plots the points (x(1), y(1)), (x(2), y(2)). In Sections 6 and 8 you will see there are two other commands to create graphs, namely fplot which uses function M-files and ezplot which is inside the Symbolic Math Toolbox.
![plot matlab plot matlab](https://www.mathworks.com/help/examples/nnet/win64/PlotVectorsUsingThePlotvFunctionExample_01.png)
In this section we will use MATLAB ’s plot command to produce graphs.