how to correct the error in the datetime?

조회 수: 2 (최근 30일)
Lilya
Lilya 2017년 9월 9일
댓글: Lilya 2017년 9월 10일
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
  댓글 수: 1
Jose Marques
Jose Marques 2017년 9월 9일
Can you explain how the errors occurs ?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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);
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 9월 10일
Start a new Question
Lilya
Lilya 2017년 9월 10일
Done.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by