필터 지우기
필터 지우기

change color in loop with scatter3?

조회 수: 2 (최근 30일)
hotait hassane
hotait hassane 2019년 4월 22일
댓글: Bob Thompson 2019년 4월 23일
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