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

1 visualización (últimos 30 días)
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

Respuesta aceptada

KSSV
KSSV el 10 de Jun. de 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 comentarios
KSSV
KSSV el 10 de Jun. de 2019
What ever ....you may make changes in the given code.
Samaneh Arzpeima
Samaneh Arzpeima el 11 de Jun. de 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')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by