loop;multi;ncread;getvar

Here's my issue Variable y=49 files, i want to create a tempdata for each y file (for y1 tempdata1).
for i=1:49 y[i]=files(i,:).name; tempdata[i]=netcdf.getVar(ncid,8); end
%%%%%%%
If that's not possible, i also have a variable - files(49x1)
i need a loop here, can't handput all files. tempdata[i]=ncread('each file from matrix file.nc','temperature');???
is that possible?
thanks

Respuestas (1)

KSSV
KSSV el 25 de Oct. de 2016

0 votos

ncfiles = dir('*.nc'); % get all nc files in the folder
nfiles = length(ncfiles) ; % total number of files
% loop for each file
for K = 1 : nfiles
filename = ncfiles(K).name; %just the name
%%get the vairable you want from nc file
T = ncread(filename,'T') ; % doc ncread
%%Append the data where you want
end

3 comentarios

daniel alves
daniel alves el 25 de Oct. de 2016
thanks Dr. Siva Srinivas Kolukula, it sort of worked but there's one small problem. The loop generates only 1 T file, it goes around all ncfiles and ends generating the final .nc file variable T.
KSSV
KSSV el 26 de Oct. de 2016
Editada: KSSV el 26 de Oct. de 2016
ncfiles = dir('*.nc'); % get all nc files in the folder
nfiles = length(ncfiles) ; % total number of files
T = cell(nfiles,1) ;
% loop for each file
for K = 1 : nfiles
filename = ncfiles(K).name; %just the name
%%get the vairable you want from nc file
T{K} = ncread(filename,'T') ; % doc ncread
%%Append the data where you want
end
You have to append T to a whole files matrix which initialized.I wrote it in comment. In the above code for all the files T is saved into cells.
Jake_K
Jake_K el 27 de Feb. de 2018
For me this does not work. It only works if I have my matlab script or function in the same directory as my .nc-files.... I tried all kind of stuff, but never was successful ... I always get the following error
Error in P_tamsat (line 29)
T = ncread(filename,'rfe');

Iniciar sesión para comentar.

Categorías

Más información sobre Agriculture en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Oct. de 2016

Comentada:

el 27 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by