필터 지우기
필터 지우기

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