how to correct the error in the datetime?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 9 Set 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 Commenti
Walter Roberson
Walter Roberson il 10 Set 2017
Start a new Question

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by