How can i plot two columns in different colors in MATLAB

1 vue (au cours des 30 derniers jours)
NN
NN le 5 Fév 2021
Commenté : NN le 6 Fév 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 commentaires
Jan
Jan le 5 Fév 2021
Did you import the data already or is this a part of the problem?
NN
NN le 5 Fév 2021
data is imported already

Connectez-vous pour commenter.

Réponse acceptée

Nora Khaled
Nora Khaled le 5 Fév 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')

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by