Thread Subject: File names from char array?

Subject: File names from char array?

From: Michael LaVigne

Date: 24 Sep, 2009 01:54:04

Message: 1 of 3

Hi everyone,

I was wondering if anyone knew how to extract a filename from a character array?
I am currently modifying a program and have changed it to run multiple runs without user input (one additional external loop).

Now what i would like to do is input the filenames that i will be outputing to in an array:
fnameindex = ['609-1.txt'; ...
             '610-1.txt'; ...
             '611-5.txt'; ...
             '612-1.txt'; ...
             '617-4.txt'; ...
             '618-5.txt'];
    fname=cellstr(fnameindex);

but when i try and use the: '609-1.txt' as a filename in fopen(fname(1),'wt') it gets an error.

is there a better way to do this? or am i just going to have to type this in each required part of my program?

Thanks in advance,
Michael.

Subject: File names from char array?

From: Godzilla

Date: 24 Sep, 2009 03:07:18

Message: 2 of 3

"Michael LaVigne" <mal209@lehigh.edu> wrote in message <h9ejfs$i1h$1@fred.mathworks.com>...
> Hi everyone,
>
> I was wondering if anyone knew how to extract a filename from a character array?
> I am currently modifying a program and have changed it to run multiple runs without user input (one additional external loop).
>
> Now what i would like to do is input the filenames that i will be outputing to in an array:
> fnameindex = ['609-1.txt'; ...
> '610-1.txt'; ...
> '611-5.txt'; ...
> '612-1.txt'; ...
> '617-4.txt'; ...
> '618-5.txt'];
> fname=cellstr(fnameindex);
>
> but when i try and use the: '609-1.txt' as a filename in fopen(fname(1),'wt') it gets an error.
>
> is there a better way to do this? or am i just going to have to type this in each required part of my program?
>
> Thanks in advance,
> Michael.

fopen(fname{1},'wt')

Subject: File names from char array?

From: Michael LaVigne

Date: 24 Sep, 2009 03:19:03

Message: 3 of 3

Thanks for your reply... i figured this out right as i saw your responce... aparently the {} and () make all the difference with char's

Thanks again-
Michael.


"Godzilla " <godzilla@tokyo.edu> wrote in message <h9enp6$qip$1@fred.mathworks.com>...
> "Michael LaVigne" <mal209@lehigh.edu> wrote in message <h9ejfs$i1h$1@fred.mathworks.com>...
> > Hi everyone,
> >
> > I was wondering if anyone knew how to extract a filename from a character array?
> > I am currently modifying a program and have changed it to run multiple runs without user input (one additional external loop).
> >
> > Now what i would like to do is input the filenames that i will be outputing to in an array:
> > fnameindex = ['609-1.txt'; ...
> > '610-1.txt'; ...
> > '611-5.txt'; ...
> > '612-1.txt'; ...
> > '617-4.txt'; ...
> > '618-5.txt'];
> > fname=cellstr(fnameindex);
> >
> > but when i try and use the: '609-1.txt' as a filename in fopen(fname(1),'wt') it gets an error.
> >
> > is there a better way to do this? or am i just going to have to type this in each required part of my program?
> >
> > Thanks in advance,
> > Michael.
>
> fopen(fname{1},'wt')

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
fopen Michael LaVigne 23 Sep, 2009 21:59:09
filename Michael LaVigne 23 Sep, 2009 21:59:09
char array Michael LaVigne 23 Sep, 2009 21:59:08
rssFeed for this Thread

Contact us at files@mathworks.com