how to correct the error in the datetime?
2 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Walter Roberson
2017-9-9
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!