Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ncread inside loop

Subject: ncread inside loop

From: Jonathan W Smith

Date: 5 Jun, 2013 21:24:08

Message: 1 of 5

Hello:

How do I read multiple netcdf files with ncread inside?

I could list every file name like this:

data_files = {'filename.nc', 'filename2.nc'}. How can I avoid this? For netcdf files, is there a command like dir for ascii and text files?

Jonathan

Subject: ncread inside loop

From: Nasser M. Abbasi

Date: 5 Jun, 2013 21:39:14

Message: 2 of 5

On 6/5/2013 4:24 PM, Jonathan W Smith wrote:
> Hello:
>
> How do I read multiple netcdf files with ncread inside?
>
> I could list every file name like this:
>
> data_files = {'filename.nc', 'filename2.nc'}. How can I avoid this?
>For netcdf files, is there a command like dir for ascii and text files?
>
> Jonathan
>

Yes, there is a command like dir in Matlab, it is called dir :)

EDU>> help dir

just do

    A=dir('*.nc')

and A will contain the names of all the .nc files in
the current folder. It is an struct array that has
one file in each struct.

--Nasser


  

Subject: ncread inside loop

From: Jonathan W Smith

Date: 6 Jun, 2013 16:15:08

Message: 3 of 5

Thanks for the response.

the ncread function for netcdf files needs the actual characters of the name. ncread('filename.nc', 'varname')

Once you have used dir to load the multiple files how do you load the actual filenames with the single quotes into ncread? Is there a netcdf file command that reads in multiple netcdf files?

This command allows you to do this: data_files = {'filename.nc', 'filename2.nc'} but, I have 44 files and do not want to write out 44 file names.

Thanks
Jonathan

"Nasser M. Abbasi" wrote in message <koob5t$bo9$1@speranza.aioe.org>...
> On 6/5/2013 4:24 PM, Jonathan W Smith wrote:
> > Hello:
> >
> > How do I read multiple netcdf files with ncread inside?
> >
> > I could list every file name like this:
> >
> > data_files = {'filename.nc', 'filename2.nc'}. How can I avoid this?
> >For netcdf files, is there a command like dir for ascii and text files?
> >
> > Jonathan
> >
>
> Yes, there is a command like dir in Matlab, it is called dir :)
>
> EDU>> help dir
>
> just do
>
> A=dir('*.nc')
>
> and A will contain the names of all the .nc files in
> the current folder. It is an struct array that has
> one file in each struct.
>
> --Nasser
>
>
>

Subject: ncread inside loop

From: Nasser M. Abbasi

Date: 6 Jun, 2013 16:41:43

Message: 4 of 5

On 6/6/2013 11:15 AM, Jonathan W Smith wrote:
> Thanks for the response.
>
> the ncread function for netcdf files needs the
>actual characters of the name. ncread('filename.nc', 'varname')

I do not know anything at all about ncread. But the file name is
there for you to use, it is in the struct returned back by dir().

>
> Once you have used dir to load the multiple files how do you
>load the actual filenames with the single quotes into ncread?
>

The file name is allready a string. Just use it as is. No need
to put '' around it.

---------------------------------
EDU>> A=dir('*.eps');

4x1 struct array with fields:

     name
     date
     bytes
     isdir
     datenum

EDU>> class(A(1).name)

char
--------------------------------

>Is there a netcdf file command that reads in multiple netcdf files?

I do not know.

>
> This command allows you to do this: data_files = {'filename.nc', 'filename2.nc'} but,
>I have 44 files and do not want to write out 44 file names.

Have you thought about using a loop? You have the names in
the data returned by dir(), all what you have to do is make a loop
to read all your netcdf files.

--Nasser

Subject: ncread inside loop

From: TideMan

Date: 6 Jun, 2013 19:56:29

Message: 5 of 5

On Friday, June 7, 2013 4:15:08 AM UTC+12, Jonathan W Smith wrote:
> Thanks for the response.
>
>
>
> the ncread function for netcdf files needs the actual characters of the name. ncread('filename.nc', 'varname')
>
>
>
> Once you have used dir to load the multiple files how do you load the actual filenames with the single quotes into ncread? Is there a netcdf file command that reads in multiple netcdf files?
>
>
>
> This command allows you to do this: data_files = {'filename.nc', 'filename2.nc'} but, I have 44 files and do not want to write out 44 file names.
>
>
>
> Thanks
>
> Jonathan
>
>
>
> "Nasser M. Abbasi" wrote in message <koob5t$bo9$1@speranza.aioe.org>...
>
> > On 6/5/2013 4:24 PM, Jonathan W Smith wrote:
>
> > > Hello:
>
> > >
>
> > > How do I read multiple netcdf files with ncread inside?
>
> > >
>
> > > I could list every file name like this:
>
> > >
>
> > > data_files = {'filename.nc', 'filename2.nc'}. How can I avoid this?
>
> > >For netcdf files, is there a command like dir for ascii and text files?
>
> > >
>
> > > Jonathan
>
> > >
>
> >
>
> > Yes, there is a command like dir in Matlab, it is called dir :)
>
> >
>
> > EDU>> help dir
>
> >
>
> > just do
>
> >
>
> > A=dir('*.nc')
>
> >
>
> > and A will contain the names of all the .nc files in
>
> > the current folder. It is an struct array that has
>
> > one file in each struct.
>
> >
>
> > --Nasser
>
> >
>
> >
>
> >

You're not listening..........
Follow Nasser's advice.
Then:
for ifile=length(A)
     t=ncread(A(ifile).name,'time');
     etc
     etc
end

Also, quit top posting.
It makes the thread hard to follow.
Put your reply UNDERNEATH.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us