I want to plot a set of points satisfying certain condition. Although, there are many points in this set satisfying the given condition, the code I am using plots only the last point. Anyone can help me to plot all these points?
5 ビュー (過去 30 日間)
古いコメントを表示
m=8;
for k=1:m;
for n=1:m;
v=n+k;
if v<= 7
plot(k,n,'b');
k
n
v
else
end
end
end
0 件のコメント
採用された回答
Daniel Sahlin
2017 年 12 月 21 日
Hi Mohammad Ali, You could probably just set a “hold on” statement after the plot, and change the style to e.g. ‘bo’ to get the individual points on the same graph.
plot(k,n,'bo'); hold on
It might however be worth considering saving k & n in vectors and making the plot after the loops depending on the application.
I hope it helps, Daniel
その他の回答 (1 件)
Are Mjaavatten
2017 年 12 月 21 日
You should specify a marker, since otherwise Matlab tries to plot a line between points. With only one point for each plot statement no line is drawn. Also, unless you instruct Matlab to "hold" the existing plot, the new plot command will clear the existing plot. Below, I have modified your code to use a ring ('o') as a marker.
m=8;
for k=1:m;
for n=1:m;
v=n+k;
if v<= 7
plot(k,n,'ob');
hold on
else
end
end
end
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!