I have a matrix of data named "D.data" and I can take sections of the matrix and assign them to a variable, like so:
A = D.data(:,89);
And I can plot two vectors taken from the initial data matrix like so:
plot(B,A)
However, when I want to take multiple rows from the starting matrix and combine them into one column vector, like this:
time = datestr(datenum(D.data(:,1:6)));
I cannot plot it anymore. It can be displayed like:
disp (time);
in which case it will display a list of times:
03-Dec-2011 05:28:36
03-Dec-2011 05:29:37
03-Dec-2011 05:30:38 ...
Why does "plot(time,A)" not work?
Here is the error it gives:
??? Error using ==> plot
Invalid first data argument
Error in ==> joan2>pushbutton1_Callback at 133
plot(time,Klystron);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> joan2 at 43
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)joan2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Thank you in advance!

 採用された回答

Chad Greene
Chad Greene 2012 年 4 月 18 日

0 投票

Matlab knows how to plot numbers, not strings! So try
time = datenum(D.data(:,1:6));
plot(time,A)
set(gca,'XTick',[min(time):((max(time)-min(time))/5):max(time)]) % set array of tick labels
datetick('x',15,'keepticks') % displays datenums as strings we understand

5 件のコメント

Chad Greene
Chad Greene 2012 年 4 月 18 日
Above, the 5 in (max(time)-min(time))/5 simply sets evenly spaced ticks. And the 15 in datetick('x',15,'keepticks') is the display format. Type help datetick into the command line for more display options.
Chad Greene
Chad Greene 2012 年 4 月 18 日
These may also be useful:
http://www.mathworks.com/matlabcentral/fileexchange/27075
http://www.mathworks.com/matlabcentral/fileexchange/32359
J
J 2012 年 4 月 18 日
This is great! Thank you very very very very much!
I realized soon after I posted the question that it (of course) couldn't plot strings, but I didn't know what else to do. So thank you!
KRUNAL
KRUNAL 2014 年 8 月 12 日
I have date in column 1 and time in column 2 and data in column three. I want to plot date/time against that data. Can anyone tell me how can I do it?
Chad Greene
Chad Greene 2014 年 8 月 13 日
KRUNAL, some combination of datenum and datevec may be the ticket. For a better answer, I recommend opening a brand new question. When you do, be specific about the format of your dates and times. When asking questions always be as specific as possible, and provide simplified examples when you can.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

J
J
2012 年 4 月 18 日

コメント済み:

2014 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by