Failed on converting date string to date number

hi all,
I have this code that I need to plot date data time vs power from excel, my code is as follow:
[num,T,vT] = xlsread('excel.xls','Sheet1'); %excel file
x = T(:,1); % Time column
y = num(:,4); % power column
% x1=datenum(0,0,0,0,x,0);
x1=datenum(x,'HH:MM');
plot(handles.axes,x1,y)
but I am getting this error:
??? DATENUM failed. Error using ==> dtstr2dtnummx Failed on converting date string to date number.
so how can I overcome this problem ??? please help..
Sam

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 7 月 28 日

1 投票

One or more of the times being input does not have the expected format.
for K = 1 : length(x)
try
x1 = datenum(x{K}, 'HH:MM');
catch
fprintf('Entry #%d is not valid, is |%s|\n', K, x{K});
end
end

6 件のコメント

Samer Husam
Samer Husam 2012 年 7 月 29 日
i am getting this error while i am using ur way...
??? Index exceeds matrix dimensions.
Error in ==> simpletab>pushbutton1_Callback at 1604 fprintf('Entry #%d is not valid, is %s\n', K, x{K});
why this error is occur ?
Walter Roberson
Walter Roberson 2012 年 7 月 29 日
Odd. Could you show us
size(x)
length(x)
Samer Husam
Samer Husam 2012 年 7 月 29 日
its:
for k = 1:35
try
x1 = datenum(x{K}, 'HH:MM');
catch
fprintf('Entry #%d is not valid, is |%s|\n', K, x{K});
end
end
Walter Roberson
Walter Roberson 2012 年 7 月 29 日
What is size(x) ? If it does not have at least 35 elements then you would get that error message.
Samer Husam
Samer Husam 2012 年 7 月 29 日
what do u mean by size(x)? what is represent ?
Walter Roberson
Walter Roberson 2012 年 7 月 29 日
d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements. If X is a scalar, which MATLAB software regards as a 1-by-1 array, size(X) returns the vector [1 1].

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

タグ

質問済み:

2012 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by