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

1 vue (au cours des 30 derniers jours)
Samaneh Arzpeima
Samaneh Arzpeima le 10 Juin 2019
Commenté : Samaneh Arzpeima le 11 Juin 2019
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

Réponse acceptée

KSSV
KSSV le 10 Juin 2019
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 commentaires
KSSV
KSSV le 10 Juin 2019
What ever ....you may make changes in the given code.
Samaneh Arzpeima
Samaneh Arzpeima le 11 Juin 2019
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')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by