change color in loop with scatter3?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hotait hassane
el 22 de Abr. de 2019
Comentada: Bob Thompson
el 23 de Abr. de 2019
Hello i have a matrix of 40 lines and i need to scatter3 in loop need to change the color with p the first 10 lines p equal 1 then automatically will be 2 at the end . i need to give color blue when p=1 and color red p=2 .how to do ?
[nbclass p] = size(Nbrc)
if p ==1
color = 'blue';
elseif p ==2
color
the problem is the color change for all start with blue and end with red . need to have blue for the first 10 and red for the last 30 .
thank you .
0 comentarios
Respuesta aceptada
Bob Thompson
el 22 de Abr. de 2019
Changing the color with the position is done with an if statement, just like you suggested.
for i = 1:size(Nbrc,1)
... % Do your stuff
if i <= 10
c = 'b';
else
c = 'r'; % I think 'r' is the code for red. You can check the manual for 'plot' linked below
end
scatter3(x,y,z,c);
end
Make sure you turn hold 'on' before the loop so that you actually plot all of the different sets of data to the same plot.
1 comentario
Bob Thompson
el 23 de Abr. de 2019
Ok, then just change your if statement to reflect that. If there is no consistency between different matrices then you're going to have a hard time running multiple matrices at once, but if there is some other condition that determines what range you choose then maybe it's worth it to make that the condition your if statement is looking for, instead of a range value.
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh 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!