Azzera filtri
Azzera filtri

Info

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

Date conversion program error

1 visualizzazione (ultimi 30 giorni)
Michael
Michael il 5 Lug 2011
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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!

Risposte (1)

Fangjun Jiang
Fangjun Jiang il 5 Lug 2011
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 Commenti
Michael
Michael il 5 Lug 2011
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 il 5 Lug 2011
No. You can't re-use the variable A. Try to make a different variable B.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by