Info

此问题已关闭。 请重新打开它进行编辑或回答。

error in gating datenum

1 次查看(过去 30 天)
Md. Moklesur Rahman
关闭: 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
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
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