if statement for colour coding data

조회 수: 3 (최근 30일)
P_L
P_L 2019년 2월 5일
편집: P_L 2019년 2월 28일
Hi,
I have latitude, longitude and depth data.
I am wanting to create a 2D plot of Lat Vs Long and plot the depth shown as a corrosponding colour indiacting its depth. I would like it to plot 2colours:
Green if depth <11.9 km
Red if depth < 19.8 km
I have created an if statement so far but it only shows the red stars
Thnak in advance! Pri

채택된 답변

Adam
Adam 2019년 2월 5일
편집: Adam 2019년 2월 5일
Create a mask:
greenDataIdx = Depth <= 11.9;
plot( Lat( greenDataIdx ), Long( greenDataIdx ), 'g*' )
hold on
...
Then plot your other data similarly. In your example there is no data with depth > 11.9. I was going to ask what happens to data > 19.8, but there isn't any. You can do the red data just the same though anyway, if any exists:
redDataIdx = Depth > 11.9 && Depth <= 19.8
An if statement where the target of the if is a vector is very rarely what you want. It will evaluate to a single scalar for the entire array.
  댓글 수: 1
P_L
P_L 2019년 2월 5일
Hi Adam, it worked!
Thank you so much
:)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by