필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Date conversion program error

조회 수: 1 (최근 30일)
Michael
Michael 2011년 7월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
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!

답변 (1개)

Fangjun Jiang
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
Michael
Michael 2011년 7월 5일
With the first method, it's now giving this error:
??? Cell contents assignment to a
non-cell array object.
Error in ==> time at 28
A{i} = hour;
Fangjun Jiang
Fangjun Jiang 2011년 7월 5일
No. You can't re-use the variable A. Try to make a different variable B.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by