I'm trying to plot 5 periodic functions on the same graph in MATLAB and I can't seem to figure out how to do it correctly. The following code will work, except that I still need to change the line style for each line so that they are easy to tell apart.(adsbygoogle = window.adsbygoogle || []).push({});

According to my book, the command used to plot with a different line style is: plot(x, y, '--')Code (Matlab M):

k = 1; %spring constant

w0 = sqrt(k);

z = 0; %Used to count the elements of y, which is used in the for loops below.

%loop to plot a periodic function for 5 different values of r, the damping coefficient.

for r = 0:0.5:2

w1 = sqrt(w0^2-(r^2/4));

for t = 0:0.1:10

z=z+1;

%Performs the calculation for each data point.

y(z) = exp(-r*t/2)*sin(w1*t);

end

%Performs the plot of each function for each iteration of the outer loop.

plot(y);

z=0;

end

However, any time I try to plot the above function using a command similar to plot(x, y), I just get a blank plot.

I've also tried using:

But this just gives me an error, saying that the inner matrices must match or something.

Any ideas?

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Line Styles in a Graph in MATLAB

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads for Line Styles Graph |
---|

C/++/# Is it possible to make graphs using C++? |

How to make thick line in 3D graphics (webGL)? |

Gambit graph |

**Physics Forums | Science Articles, Homework Help, Discussion**