How can i plot two columns in different colors in MATLAB

1 Ansicht (letzte 30 Tage)
NN
NN am 5 Feb. 2021
Kommentiert: NN am 6 Feb. 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 Kommentare
Jan
Jan am 5 Feb. 2021
Did you import the data already or is this a part of the problem?
NN
NN am 5 Feb. 2021
data is imported already

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Nora Khaled
Nora Khaled am 5 Feb. 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')

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by