Why plot is over plotted?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
%i degree for curve fitting
%j is the iterating number for subplot title
x=[1:10]
y=sin(x)
for i=10:10:100
title([' degree = ' ,num2str(i)])
for j=1:10
subplot(10,1,j)
p= polyfit(x,y,i)
x2=[1:0.01:10]
y2=polyval(p,x2)
plot(x,y,'o',x2,y2,'-b')
hold on
end
end
採用された回答
Jan
2018 年 7 月 11 日
x = 1:10; % No need for square brackets
y = sin(x);
for k = 1:10
% NextPlot='add' is the same as "hold on"
AxesH(k) = subplot(10, 1, k, 'NextPlot', 'add');
end
x2 = 1:0.01:10;
for i = 10:10:100
for j = 1:10
p = polyfit(x,y,i);
y2 = polyval(p,x2);
plot(AxesH(j), x,y,'o', x2,y2,'-b');
end
end
subplot clears formerly existing axes objects. So create the axes at first and use them as parent object as first input to plot.
7 件のコメント
madhan ravi
2018 年 7 月 11 日
But I want to see degree of polynomial in each subplot?
Jan
2018 年 7 月 11 日
Please explain it. What do you want to see where? In your original code you had a
title([' degree = ' ,num2str(i)])
But this was overwritten in each iteration over i. I do not understand the purpose of the inner loop over j at all. Is it intended that all diagrams have the same contents?
madhan ravi
2018 年 7 月 11 日
I want to see the degree of polynomial in each subplot and eac subplot is curve fitted according to i , I don’t know how use loop in this scenario , if you could help me debug the code I would be so thankful.
Jan
2018 年 7 月 12 日
I want to see the degree of polynomial in each subplot
Please, madhan ravi, remember that I cannot read your mind. How do you want to "see" this? By a legend and lines in different colors? By a title above each subplot? By different markers for the lines? By annotations or text beside the lines?
I cannot help you to debug the code, when it is not clear, what the bug is. What do you want to achieve?
madhan ravi
2018 年 7 月 12 日
Sorry jan for being unclear . All I want to do is like the example below: T The first subplot title should be 10.
The second subplot title should be ‘20’.
The third subplot title should be ‘30’
The fourth subplot title should be ‘40’.
The fifth subplot title should be ‘50’
The sixth subplot title should be ‘60’
The seventh ‘70’
The eighth ‘80’
The nineth ‘90’
The last ‘100’.
This is what I need .
I highly appreciate your desperation to help me.
Jan
2018 年 7 月 12 日
You are welcome, madhan ravi. This is a forum for Matlab questions :-)
Insert a line to draw the title in the first loop to create the axes:
for k = 1:10
% NextPlot='add' is the same as "hold on"
AxesH(k) = subplot(10, 1, k, 'NextPlot', 'add');
title(AxesH(k), sprintf('%d', k * 10));
end
Does this help?
madhan ravi
2018 年 7 月 12 日
編集済み: madhan ravi
2018 年 7 月 12 日
Awesome!! Thank you so much @jan.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Discrete Data Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
