Problem with plotting two lines on the same graph using different line types.

I was assigned a problem asking to plot two "butterfly plots". I am to plot two lines on one graph one using a solid line and the other using a dotted line. I have tried using plot(x,t,'-',y,t,':'). and I have tried them separately with the hold on command to not lose the existing data. Either way I can not get the dotted line to appear on the plot. Does Matlab have an override for plots containing too many data points. The code so far looks like this:
t=0:.0625:100; x=sin(t')*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5); y=cos(t')*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5); subplot(2,1,1),plot(x,t,'-'),hold on,plot(y,t,':'),hold off legend('x','y'),hleg1=legend('x','y'),set(hleg1,'Location','EastOutside') title('x and y versus t') xlabel('values of x and y') ylabel('values of t') hold off subplot(2,1,2),plot(y,x) title('y versus x') xlabel('values of y'),ylabel('values of x') axis square
Any help or suggestions would be greatly appreciated.

1 Comment

My first suggestion is to format your code so it is readable: see http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question.

Sign in to comment.

 Accepted Answer

Your equations for x and y use matrix multiplication, resulting in a 1601 x 1601 matrix. Use element-by-element multiplication ( .* ) instead:
x=sin(t).*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5);
y=cos(t).*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5);

2 Comments

Thanks for the help on this Andrew. Could you elaborate on why the dot comes before the multiplication sign. Earlier I thought it had to be a combination of using the period for the element by element multiplication but thought that it would come before the variable in the cos and sin operations. Also the link you gave says something about clicking on the mark up button before entering code. So to ask a question I would type normally, like now but before entering the code click the mark up and then enter the code then unclick it to go back to regular typing? Thanks for the help and I'm going to accept the answer I just wanted to make sure you got to see the post.
I went back in to ask a question to see what you were talking about and found the button for entering code. Also I looked up the (.*)command and see that it is element wise array multiplication. I will try to remember to submit my code in the specified way. Thanks for your time.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!