How to plot two columns when another column has a specified value

조회 수: 1 (최근 30일)
Samaneh Arzpeima
Samaneh Arzpeima 2019년 6월 10일
댓글: Samaneh Arzpeima 2019년 6월 11일
Hello
I have an excel file
I need to plot two of the columns when another column has a specified value(string)
The following code does not work, I want to have red circle when the 2nd column is "dipslip" and blue stars when 2nd column is "strikeslip"
filename = 'sim_result.xlsx';
sheet = 1;
[num,txt,raw] = xlsread(filename,sheet)
Area=cell2mat(raw(2:end,3));
moment=cell2mat(raw(2:end,5));
type=raw((2:end),2);
%scatter(cell2mat(raw(2:end,3)),cell2mat(raw(2:end,5)))
scatter(moment(type=='dipslip'),Area(type=='dipslip'),'or')
scatter(moment(type=='strikeslip'),Area(type=='strikeslip'),'sr')
How can I do this
Thank you
p.s. I can not use gscatter

채택된 답변

KSSV
KSSV 2019년 6월 10일
idx1 = contains(type,'dipslip') ;
idx2 = contains(type,'strikeslip') ;
figure
hold on
plot(moment(idx1),Area(idx1),'Or')
plot(moment(idx2),Area(idx2),'sr')
If contains is not available, use strcmp
  댓글 수: 3
KSSV
KSSV 2019년 6월 10일
What ever ....you may make changes in the given code.
Samaneh Arzpeima
Samaneh Arzpeima 2019년 6월 11일
thank you
I got what I've needed with the following lines.is there any way to make it look more smarter
filename = 'sim_result.xlsx';
sheet = 1;
% xlRange = 'B2:C3';
[num,txt,raw] = xlsread(filename,sheet)
% subsetA = xlsread(filename,sheet,xlRange)
Area=cell2mat(raw(2:end,3));
moment=cell2mat(raw(2:end,5));
type=raw((2:end),2);
S=cell2mat(raw(2:end,1));
idx1 = contains(type,'dipslip') & S>1;
idx12 = contains(type,'dipslip') & S==1;
idx13 = contains(type,'dipslip') & S<1;
idx2 = contains(type,'strikeslip') & S>1;
idx21= contains(type,'strikeslip') & S==1;
idx22 = contains(type,'strikeslip') & S<1;
figure
hold on
plot(moment(idx1),Area(idx1),'Or')
plot(moment(idx12),Area(idx12),'Ob')
plot(moment(idx13),Area(idx13),'Og')
plot(moment(idx2),Area(idx2),'*r')
plot(moment(idx21),Area(idx21),'*b')
plot(moment(idx22),Area(idx22),'*g')

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by