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')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by