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

采纳的回答

Daniel Sahlin
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
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 CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by