Info
此问题已关闭。 请重新打开它进行编辑或回答。
Date conversion program error
1 次查看(过去 30 天)
显示 更早的评论
I have a program that finds the time column in a data sheet (in unix time) and takes each time value and makes a new excel document and converts it into the hour.
Here's the code I made for it: fileid=['sitedata.csv']; [data, text] = xlsread(fileid); col = strcmpi(text(1,:),'Time'); A = data(:,col); for i = 1:length(A) X = datenum([1970 1 1 0 0 A(i)]); hour = datestr(X, 'HH'); A(i) = hour; end
When I run it the error I get is: ??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> time at 28
A(i) = hour;
Any ideas how to fix this? Thank you!
0 个评论
回答(1 个)
Fangjun Jiang
2011-7-5
In your code, "A" is a double array, "hour" is a char array. If you change A(i)=hour to B{i}=hour, it will work. But it's better to pre-allocate B as a cell array right before the for-loop B=cell(size(A));
2 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!