Thread Subject: basic MATLAB question

Subject: basic MATLAB question

From: Kim

Date: 13 Nov, 2009 09:00:30

Message: 1 of 8

I have a script where I input specific columns from a ascii file and perform a function on them. Is it possible to set the name, of the file I import, as some kind of variable so that I don't have to write the filename over and over for each time I import it?

This is how I do it now:

x = dlmread('asciifile', '\t', 'A1..A100');
y = dlmread('asciifile', '\t', 'B1..B100');

I want to be able to do something like this:

filename = 'asciifile'

x = dlmread('filename', '\t', 'A1..A100');
y = dlmread('filename', '\t', 'B1..B100');

xlswrite('fielanmeoutput.xls', out, 'output', 'A1')
xlswrite('fielanmeoutput.xls', out, 'output', 'B1')

Subject: basic MATLAB question

From: Kim

Date: 13 Nov, 2009 12:09:26

Message: 2 of 8

bump

Subject: basic MATLAB question

From: Dave Robinson

Date: 13 Nov, 2009 12:25:05

Message: 3 of 8

Kim <kili@kth.se> wrote in message <1484051125.10969.1258114196390.JavaMail.root@gallium.mathforum.org>...
> bump

I am not quite sure this is what you need but have you looked at

uigetfile( ... );

and its mate

uiputfile( ... );

Regards

Dave Robinson

Subject: basic MATLAB question

From: Thomas

Date: 13 Nov, 2009 12:42:02

Message: 4 of 8

Just omit the quotes when passing the filename to the function:

filein = 'asciifile';
 
x = dlmread(filein' '\t', 'A1..A100');
y = dlmread(filein, '\t', 'B1..B100');

fileout = 'fielanmeoutput.xls';

xlswrite(fileout, out, 'output', 'A1');
xlswrite(fileout, out, 'output', 'B1');

Subject: basic MATLAB question

From: Kim

Date: 13 Nov, 2009 15:00:49

Message: 5 of 8

Thank you, worked great!

Is it possible to have the output file named after the inputfile but with the ending "output" in the end of it?

For example, I open a file named "datafile" and want to save the file as "datafile_output" without having to write the output filename each time. Is this possible?

Subject: basic MATLAB question

From: ImageAnalyst

Date: 13 Nov, 2009 15:17:44

Message: 6 of 8

On Nov 13, 10:00 am, Kim <k...@kth.se> wrote:
> Thank you, worked great!
>
> Is it possible to have the output file named after the inputfile but with the ending "output" in the end of it?
>
> For example, I open a file named "datafile" and want to save the file as "datafile_output" without having to write the output filename each time. Is this possible?

-------------------------------------------------------------
I always like sprintf() for doing this kind of thing.
You may also get use out of fileparts() and fullfile().

Subject: basic MATLAB question

From: Kim

Date: 13 Nov, 2009 15:59:21

Message: 7 of 8

ok, I'm not sure how to use sprintf(), how would I go about saving my file with the same name as the the input file but with the ending "_output.xls"?

Subject: basic MATLAB question

From: dpb

Date: 13 Nov, 2009 16:04:06

Message: 8 of 8

Kim wrote:
> ok, I'm not sure how to use sprintf(), how would I go about saving my
> file with the same name as the the input file but with the ending
> "_output.xls"?

See TMW FAQ at the wiki site--I forget the url; it's in Steven Lord's
sig block.

See the FAQ on "how do I save/open fileN" or similar title--it's got
examples of creating dynamic file names.

As Matt says,

doc fileparts

will undoubtedly be helpful in your particular case.

--

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com