Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Undefined operator '==' for input arguments of type 'struct'. netcdf files
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
jessupj
el 9 de Jun. de 2020
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.
Respuestas (1)
Chidvi Modala
el 12 de Jun. de 2020
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 comentario
jessupj
el 12 de Jun. de 2020
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.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!