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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Ali
el 21 de Dic. de 2017
Comentada: Mohammad Ali
el 23 de Dic. de 2017
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 comentarios
Respuesta aceptada
Daniel Sahlin
el 21 de Dic. de 2017
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
Más respuestas (1)
Are Mjaavatten
el 21 de Dic. de 2017
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
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!