how can i draw some points but diferent colors depends of a condition?

조회 수: 1 (최근 30일)
while n<= l
if 0<d(p)<=10
h=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','b');
elseif 10<d(p)<= 20
h=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','y');
elseif 30<d(p)<= 40
h=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','m');
else
h=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','g');
end
p=p+1;
n=n+1;
end
thats the code basicly, i wanna draw the point of a specific color if the distance between 2 points are between 0 and 10, for example this point should be blue.
continue the cycle we check de distance from the next point, to know whats the distance and draw it with the respect color.
currently the issue is every point is blue, because its the first condition, if i change this blue for another color then all points will be of this color, it seems like only takes the first one.
if someone can help please :(

채택된 답변

Walter Roberson
Walter Roberson 2022년 6월 19일
if 0<d(p)<=10
MATLAB interprets that as
if ((0<d(p))<=10)
The first comparison is made, 0<d(p) giving you a response of 0 (false) or 1 (true). Then that 0 or 1 is compared to 10 -- and since both 0 and 1 are <= 10, the result is always true.
  댓글 수: 1
Erick Guzman
Erick Guzman 2022년 6월 19일
thanks, you answer open my mind but you dont tell me how do it literally hahahha.
thanks so much.
i do it with:
if (dm(p)<=10)
h1=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','g');
elseif (10<dm(p) && dm(2)<= 20)
h1=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','y');
elseif (20<dm(p) && dm(2)<= 30)
h1=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','b');
else
h1=images.roi.Point(gca,'Position',[x(n) y(n)],'Color','b');
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by