How can i plot two columns in different colors in MATLAB

3 visualizaciones (últimos 30 días)
NN
NN el 5 de Feb. de 2021
Comentada: NN el 6 de Feb. de 2021
can someone suggest me how to plot 2nd and 3 rd column in x axis in differnt colors as scatter plot against the 1st column as y axis ?
  3 comentarios
Jan
Jan el 5 de Feb. de 2021
Did you import the data already or is this a part of the problem?
NN
NN el 5 de Feb. de 2021
data is imported already

Iniciar sesión para comentar.

Respuesta aceptada

Nora Khaled
Nora Khaled el 5 de Feb. de 2021
check out this code I wrote... is it what you want ?
%data colomns
x={2,4,8,9,3};
a={'3:17:00 AM';'5:06:30 AM' ;'7:18:00 AM'; '10:30:30 AM' ;'9:19:00 AM'};
b={'3:17:00 PM';'5:06:30 PM' ;'7:18:00 PM'; '1:30:30 PM' ;'11:19:00 PM'};
%remove AM and PM
a=cellfun(@(x) erase(x," AM"),a,'UniformOutput',false);
b=cellfun(@(x) erase(x," PM"),b,'UniformOutput',false);
%change time format to have double digit hours hh:mm:ss
inda=find(cellfun('size',a,2)==7);
indb=find(cellfun('size',b,2)==7);
a(inda,1)=strcat('0',a(inda,1));
b(indb,1)=strcat('0',b(indb,1));
%convert cells to arrays
x=cell2mat(x);
a=cell2mat(a);
b=cell2mat(b);
%convert string to time
Time2plot_a = datetime(a, 'inputformat','hh:mm:ss', 'Format','hh:mm:ss');
Time2plot_b = datetime(b, 'inputformat','hh:mm:ss', 'Format','hh:mm:ss');
%plot
scatter(Time2plot_a,x,'b.')
hold on
scatter(Time2plot_b,x,'r.')
legend('AM','PM')

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by