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 件のコメント

Andrew Newell
Andrew Newell 2012 年 1 月 23 日
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.

サインインしてコメントする。

 採用された回答

Andrew Newell
Andrew Newell 2012 年 1 月 23 日
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 件のコメント

Adam Anderson
Adam Anderson 2012 年 1 月 23 日
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.
Adam Anderson
Adam Anderson 2012 年 1 月 23 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by