Undefined operator '==' for input arguments of type 'struct'. netcdf files
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
I'm trying to do a loop to open netcdf files (14 files) and to extract some variables(temperature, salinity and velocity). This is what I've got so far. But I get the error:
Undefined operator '==' for input arguments of type 'struct'.
And I don't understand how to fix it. I know it must be something very simple, but I'm still quite new with matlab. Thanks for your time
clear
myFolder = ('C:\modelana\netcdf_2019\');
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
ncFilename = dir([myFolder '*.nc']);
for k = 1:length(ncFilename)
myfolder = fullfile(ncFilename(k).folder,ncFilename(k).name);
if isempty(ncFilename == 1)
continue;
else
ncfile =([myFolder ncFilename]);
s(k,:) = ncread(ncfile,'salinity') ;
t(k,:) = ncread(ncfile,'temp') ;
u(k,:) = ncread(ncfile,'u') ;
end
end
댓글 수: 4
KSSV
2020년 6월 9일
isempty(ncFilename)
Ana Corrochano
2020년 6월 9일
jessupj
2020년 6월 9일
where it that occurring? i suspect that it doesn't like
[myFolder ncFilename]
because you're trying to concatenate a string (my Folder) with whatever kind of non-string object 'ncFilename' is. Note that 'ncFilename' is the object whose length you're iterating over in the loop. You maybe need:
[myFolder ncFilename(k).name] % or something like that.
Just a tip on some other programming: it looks like you use both 'myfolder' and 'myFolder' as different variables. I would avoid that by calling them something more distinguishable, like 'folder1' and 'folder2' so that 'errors' and 'typos' are easier to tell apart.
per isakson
2020년 6월 9일
답변 (1개)
Chidvi Modala
2020년 6월 12일
In the provided code the resultant variable 'ncFilename' is of struct datatype. By doing this ([myFolder ncFilename]) operation you are trying to concatenate a struct with character array. Hence the error. To avoid the error, you can replace ([myFolder ncFilename]) with something like below
ncfile =([myFolder ncFilename(k).name]);
To get a proper ncfile value, you might need to add '\' as shown below
ncfile =([myFolder '\' ncFilename(k).name]);
To know more about 'struct' datatype you can refer to this
댓글 수: 1
jessupj
2020년 6월 12일
OP's 'myFolder' already includes the backslash, so the second line of code here isn't necessary. Just use the first one as we both suggested. Also, one wouldn't need need parenteses around brackets.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!