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?
조회 수: 1 (최근 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!