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 Center および File ExchangeData Import from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by