Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

error in gating datenum

1 visualizzazione (ultimi 30 giorni)
Md. Moklesur Rahman
Md. Moklesur Rahman il 6 Set 2012
Chiuso: MATLAB Answer Bot il 20 Ago 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!]

Risposte (1)

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

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by