Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to make a plot with different colors to represent different data values/thresholds?

조회 수: 1 (최근 30일)
Ivy Chen
Ivy Chen 2018년 6월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
I need to generate a plot have a couple of elements below: ▪ Small dots when State 5 = green, State 3 = yellow ▪ Big circles when thresholds occur: State 5 = orange, State 3 = red
Appreciate tips/assistance on this.

답변 (1개)

D. Plotnick
D. Plotnick 2018년 6월 28일
You can use a nested switch-case statement. Lets say you have data x,y,state1,state2.
switch state1
case 5
switch state2
case 1
markerSize = 3;
color = 'r'
marker = '.'
case 2
""
""
""
end
case 3
""
""
""
end
end
mn = [color,marker]
plot(x,y,mn,'MarkerSize',markerSize);
You should be able to fill in the rest: nested switches are good for this, you will just have to appropriately define you cases for each switch.
  댓글 수: 3
Ivy Chen
Ivy Chen 2018년 7월 2일
Daniel, I have difficulty of get this to work. Basically, this is what I am trying to achieve. Appreciate any help that you might able to provide. thanks again.
scatter(C_N04,VE,5);
for k=1:length(C_N04)
if strcmp(Tracking,'TRUE')
if C_A_code_tracks==1
set(gcf, 'markerSize',2, 'color','yellow', 'marker','.')
elseif C_A_carrier==1
set(gcf, 'markerSize',2, 'color','green', 'marker','.')
else
set(gcf, 'markerSize',2, 'color','black', 'marker','-')
end
elseif strcmp(Tracking,'FALSE')
if C_A_carrier_tracks==0
set(gcf, 'markerSize',2, 'color','orange', 'marker','o')
elseif C_A_coade_tracks==0
set(gcf, 'markerSize',2, 'color','red', 'marker','o')
else
set(gcf, 'markerSize',2, 'color','black', 'marker','-')
end
end
Ivy Chen
Ivy Chen 2018년 7월 2일
this is what I have, but it says that "SWITCH expression must be a scalar or string constant." Not sure where the mistake is... thanks for help.
C_N04 = TexasPorkButt.C_N04(Idx);
VE = TexasPorkButt.True_VE(Idx);
Tracking = TexasPorkButt.Tracking(Idx);
Code_T = TexasPorkButt.C_A_code_tracks(Idx);
Carrier_T = TexasPorkButt.C_A_carrier_tracks(Idx);
switch Tracking
case strcmp(Tracking,'TRUE')
switch (Code_T)
case 0
markerSize = 3;
color = 'black';
marker = '-';
case 1
markerSize = 3;
color = 'yellow';
marker = '.';
end
switch (Carrier_T)
case 1
markerSize = 3;
color = 'green';
marker = '.';
end
case strcmp(Tracking,'FALSE')
switch (Carrier_T)
case 0
markerSize = 3;
color = 'orange';
marker = 'o';
end
switch (Code_T)
case 0
markerSize = 3;
color = 'red';
marker = 'o';
end
end
mn = [color,marker];
plot(C_N04,VE,mn,'MarkerSize',markerSize);

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by