How can i plot two columns in different colors in MATLAB

1 回表示 (過去 30 日間)
NN
NN 2021 年 2 月 5 日
コメント済み: NN 2021 年 2 月 6 日
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 件のコメント
Jan
Jan 2021 年 2 月 5 日
Did you import the data already or is this a part of the problem?
NN
NN 2021 年 2 月 5 日
data is imported already

サインインしてコメントする。

採用された回答

Nora Khaled
Nora Khaled 2021 年 2 月 5 日
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')
  1 件のコメント
NN
NN 2021 年 2 月 6 日
thanks very much .It worked .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by