From: Matt on
Hi there,

I'm trying to make make a loop that executes the same operation on 11 netCDF files that are all stored in the same folder. It plots the first variable from each netCDF file.
Each file is named from 1 to 11 in the folder.


My code is so far:

for f = 1:11
UK = netcdf.open('f.nc','NC_NOWRITE');
[varname, vartype, dimids, natts] = netcdf.inqVar(UK,0)

abc = netcdf.getVar(UK,0);

abc(abc==-32768)=0;

plot = imagesc(abc);

I = getframe(gcf);
imwrite(I.cdata, 'f.png');
end


I get this error when I run it:

??? Error using ==> open at 44
The specified file does not exist.

Error in ==> loop at 2
UKMOSST = netcdf.open('f.nc','NC_NOWRITE');


If anyone can help that would be great!
Thanks!
From: dpb on
Matt wrote:
> Hi there,
>
> I'm trying to make make a loop that executes the same operation on 11
> netCDF files that are all stored in the same folder. It plots the first
> variable from each netCDF file. Each file is named from 1 to 11 in the
> folder.
>
>
> My code is so far:
>
> for f = 1:11
> UK = netcdf.open('f.nc','NC_NOWRITE');
....

>
> I get this error when I run it:
> ??? Error using ==> open at 44
> The specified file does not exist.
>
> Error in ==> loop at 2
> UKMOSST = netcdf.open('f.nc','NC_NOWRITE');
>
>
> If anyone can help that would be great!

'f.nc' is a string so you're trying to open a file name f.nc which, in
all likelihood, _doesn't_ exist, just like the open statement says.

See the FAQ 4.12 at the matlab wiki (matlabwiki.matlab.com)

--