how to correct the error in the datetime?

1 Ansicht (letzte 30 Tage)
Lilya
Lilya am 9 Sep. 2017
Kommentiert: Lilya am 10 Sep. 2017
Hi all,
I wrote the following script to extract some data from the list of files. The date time matrix is still shown some errors that I want to have it as double array, could anyone help me how to correct it?
Thank you so much.
a = dir('*.tuv'); %counting the number of profiles
b = length(a);
% creat NaNs matrix to import the extracted data
time = ones(978,length(b)) * NaN; %this is the error
tG = ones(978,length(b)) * NaN;
U = ones(978,length(b)) * NaN;
V = ones(978,length(b)) * NaN;
for i = 1:numel(a);
c = load(a(i).name);
hh=tuv2hfrc(a(i).name); %the related files that needs in the time extraction
time(1:m,i) = {[hh.matlab_time]}; % this as well
[m n] = size(c);
lat1 = c(:,1);lon1 = c(:,2);u = c(:,3);v = c(:,4);
Lat(1:m,i) = lat1;Lon(1:m,i) = lon1;U(1:m,i) = u;V(1:m,i) =v;
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Sep. 2017
You have
time = ones(978,length(b)) * NaN; %this is the error
so you initialize time as being a numeric array. However, you later have
time(1:m,i) = {[hh.matlab_time]}; % this as well
so you are trying to store a cell array into a numeric slot.
Also notice that you have
b = length(a);
so b is a scalar that contains the length of a. and you have
time = ones(978,length(b)) * NaN; %this is the error
but with b being a scalar, length(b) is certain to be 1, suggesting that you have miscoded here. Perhaps you wanted
time = ones(978,b) * NaN;
or more simply
time = nan(978,b);
  3 Kommentare
Walter Roberson
Walter Roberson am 10 Sep. 2017
Start a new Question
Lilya
Lilya am 10 Sep. 2017
Done.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by