Ignoring extra legend entries?

16 ビュー (過去 30 日間)
Charlotte Davies
Charlotte Davies 2017 年 5 月 17 日
コメント済み: Charlotte Davies 2017 年 5 月 17 日
My function is supposed to graph all three values of y against x, but instead it graphs the first two and I receive the error notice: Warning: Ignoring extra legend entries. How can I resolve this? My code is below:
X = -10:0.2:10; y1 = X.^2; y2 = X.*cos(X) y3 = -X.^3 plot(x,y1,y2,y3);
%set the domain and range axis([-10 10 -10 10]);
title('Comparing functions') xlabel('x') ylabel('y') legend('y1=x^2','y2=xcos(x)','y3=-x^3')
print('module04.png','-dpng')

採用された回答

David Goodmanson
David Goodmanson 2017 年 5 月 17 日
編集済み: David Goodmanson 2017 年 5 月 17 日
Hello Charlotte, you should be getting a pretty strange graph right now, since it would be plotting x vs y1 and then y2 vs y3. try
plot(X,[y1;y2;y3]);
which creates a matrix of y arrays and uses the X array as the independent variable all three times.
  1 件のコメント
Charlotte Davies
Charlotte Davies 2017 年 5 月 17 日
Thank you! Haha whoops no wonder it was looking so strange...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by