how can i plot data of different types using matlab plot(x,y) ?

조회 수: 6 (최근 30일)
Isma
Isma 2015년 2월 26일
댓글: Star Strider 2015년 2월 26일
Hi
after importing my data into matlab as a cell array, i am wondering how to plot my time series. The issue is coming from the treatment of my date column (first column) which is imported as text. i did not experience any issue with the remaining columns since i used cell2mat to convert cells data into double (requirement for plotting).
any idea would be appreciated. Thanks

답변 (3개)

michael scheinfeild
michael scheinfeild 2015년 2월 26일
you can try to conver each of cell array by split 23/05/15 to 3 parts by search "/" the you can code it to index = year*10+month*10+day the plot it

Star Strider
Star Strider 2015년 2월 26일
I don’t know what your cell array looks like once you have imported your data. Taking a guess, this is how I would do it:
C = {['1/27/2015';'1/26/2015';'1/23/2015';'1/22/2015';'1/21/2015';'1/20/2015'], rand(6,1)*108,rand(6,1)};
DN = datenum(C{1}, 'mm/dd/yyyy');
figure(1)
subplot(2,1,1)
plot(DN, C{2})
datetick('x', 'mm/dd/yyyy')
set(gca, 'FontSize', 8) % Optional
grid
subplot(2,1,2)
plot(DN, C{3})
datetick('x', 'mm/dd/yyyy')
set(gca, 'FontSize', 8) % Optional
grid
  댓글 수: 2
Isma
Isma 2015년 2월 26일
hi Thanks for the feedback. as my data is (2945*3), could your syntax handle with C={[data(:,1),rand(6,1)*108,rand(6,1)}; also could you explain me a bit about why plot(DN, C{2})? acknowledging DN is my x-axis. why C{2} or could you confirm C{2} = rand(6,1)*108,rand(6,1)+ Y-absciss for my understanding ? cheers
Star Strider
Star Strider 2015년 2월 26일
If your data are all in one cell, you would have to do the subscripting differently, but the rest of my code should work. I don’t have your data to work with, so I can’t be more specific.

댓글을 달려면 로그인하십시오.


Brendan Hamm
Brendan Hamm 2015년 2월 26일
편집: Brendan Hamm 2015년 2월 26일
If your version is 2014a or less then you can use (assuming your cell array is named 'x')
% This converts date strings to MATLAB serial date numbers
myDate = datenum(x(:,1));
plot(myDate,y); %for some numeric vector y
datetick
There are more options you can use for datenum and datetick so look at the documentation.
If your version is later than this (currently only 2014b is) then you can use the new datetime variable.
myDate = datetime(x(:,1),...); % You will need to provide the input format thus the ...
% datetimes can be plotted directly:
plot(myDate,y);
  댓글 수: 2
Isma
Isma 2015년 2월 26일
hi your solution seems to be the quickest and easiest to implement as my cell data dimension is (2945*3). however
myDate=datenum(abrxeur{:,1})
Error using datenum
Too many input arguments.
any idea? i am using version 2013a version
Brendan Hamm
Brendan Hamm 2015년 2월 26일
편집: Brendan Hamm 2015년 2월 26일
Oops. Those braces should be parenthesis. My apologies. I have updated the solution.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by