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

1 次查看(过去 30 天)
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 个评论
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