Regarding reading diffrent files
Mostrar comentarios más antiguos
I have some .nc files for 13 years (13 files) e.g GTE_bb_CH_1997.nc,GTE_bb_CH_1998.nc,...., GTE_bb_CH_2009.nc I want to read and plot all files same time. So how I can write loop so I can read separate file for every year ?
Respuestas (1)
Fangjun Jiang
el 19 de Sept. de 2011
Files=dir('*.nc');
for k=1:length(Files)
FileName=Files(k).name;
%load file
end
7 comentarios
Uday
el 19 de Sept. de 2011
Fangjun Jiang
el 19 de Sept. de 2011
That depends. What is .nc file? There is no built-in function to load .nc file directly. If it's a text file, you have to understand its format and then load it use uiimport(),importdata(), textscan() or fopen(), fread().
Uday
el 19 de Sept. de 2011
Uday
el 19 de Sept. de 2011
Fangjun Jiang
el 19 de Sept. de 2011
Okay, Thank you! I learned netcdf() today! It is reading all files. But you are over-writing the data every time, right? You need to add an "end" line to complete the for-loop. To store data for every file, you need to declare an array before the for-loop. Something like latitude=zeros(length(dir_list),1). Then, inside the for-loop, use latitude(i)=double(netcdf.getVar(ncid,latid));
Uday
el 19 de Sept. de 2011
Fangjun Jiang
el 19 de Sept. de 2011
Try this:
dir_list=dir('*.nc');
for i=1:length(dir_list)
FileName=dir_list(i).name
end
Do you see 13 file names appear in the Command Window?
Categorías
Más información sobre Standard File Formats en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!