Effacer les filtres
Effacer les filtres

change color in loop with scatter3?

2 vues (au cours des 30 derniers jours)
hotait hassane
hotait hassane le 22 Avr 2019
Commenté : Bob Thompson le 23 Avr 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 .

Réponse acceptée

Bob Thompson
Bob Thompson le 22 Avr 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 commentaire
Bob Thompson
Bob Thompson le 23 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by