change color in loop with scatter3?

2 次查看(过去 30 天)
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 .

采纳的回答

Bob Thompson
Bob Thompson 2019-4-22
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 个评论
Bob Thompson
Bob Thompson 2019-4-23
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by