Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

error in gating datenum

1 Ansicht (letzte 30 Tage)
Md. Moklesur Rahman
Md. Moklesur Rahman am 6 Sep. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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!]

Antworten (1)

Jan
Jan am 6 Sep. 2012
Bearbeitet: Jan am 6 Sep. 2012
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 Kommentare
Md. Moklesur Rahman
Md. Moklesur Rahman am 6 Sep. 2012
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 am 7 Sep. 2012
Ohhh it did work with B = datenum(Q) that did not work first.
There was something wrong in the file.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by