フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

error in gating datenum

1 回表示 (過去 30 日間)
Md. Moklesur Rahman
Md. Moklesur Rahman 2012 年 9 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello everyone,
I am using the following matlab code make a datevector:
close all;clc;
A = xlsread('RGM.xlsx');
Q = textdata(2:end,1);
B = datenum(Q);
B = datestr(B, 'yyyy-mm-dd HH:MM:SS');
timevec = datevec(B);
But while matlab attempts to execute the 4th line of my code I am getting the following error:
??? Error using ==> datenum at 182 DATENUM failed.
Caused by: Error using ==> dtstr2dtnummx Failed on converting date string to date number.
Then I applied the following code based on a solution from mathworks which did work for one of the matlab users:
close all;clc;
A = xlsread('SS file.xlsx');
Q = textdata(2:end,1);
B = datenum([Q{:}],'mm-dd-yyyy HH:MM:SS');
B = datestr(B, 'yyyy-mm-dd HH:MM:SS');
timevec = datevec(B);
The above code worked but for only one (the first) element. But I want the code to work for all the elements. The properties in my workspace is as follows:
>> whos Name Size Bytes Class Attributes
A 145756x8 9328384 double
Q 146351x1 14707352 cell
data 145756x8 9328384 double
textdata 146352x9 85455076 cell
Can anybody help me please. Thank you very much in advance for helping me to get rid of this problem.
[EDITED, Jan, code formatted - please do this by your own in the future - Thanks!]

回答 (1 件)

Jan
Jan 2012 年 9 月 6 日
編集済み: Jan 2012 年 9 月 6 日
Please try:
B = datenum(Q, 'mm-dd-yyyy HH:MM:SS');
or the less efficient:
B = datenum(cat(1, Q{:}), 'mm-dd-yyyy HH:MM:SS');
Your "[Q{:}]" is equivalent to cat(2, q{:}) and creates a long string like this:
'03-14-2012 12:13:1403-14-2012 12:13:1403-14-2012 12:13:14...'
And this confuses DATENUM.
  2 件のコメント
Md. Moklesur Rahman
Md. Moklesur Rahman 2012 年 9 月 6 日
Dear Jan,
Thank you very much for your heartiest afford. I really appreciate that. Among the two options you mentioned I tried the first one that did not work. However, for the second option I am getting an error as follows:
??? Error using ==> cat
CAT arguments dimensions are not consistent.
Do you have any idea why this is happening ?
Thanks again.
Md. Moklesur Rahman
Md. Moklesur Rahman 2012 年 9 月 7 日
Ohhh it did work with B = datenum(Q) that did not work first.
There was something wrong in the file.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by