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:
Running a batch of pairs of files

Subject: Running a batch of pairs of files

From: Charles Dillon

Date: 28 Jun, 2011 13:27:04

Message: 1 of 3

I have what I assume is a dumb question, yet I cannot find an answer to it.
I want to write a programme to run a bunch of tests through a function and store the answers produced. Each run of the function requires two files, and each file has a pair with which it must be run. Something like:
runfile('1a.txt', '2a.txt');
where 1a.txt and 2a.txt are a pair of files.
How could I get a program to run each pair of files? I assume I should first separate the two types of files into separate folders. Once I do that, and they are in the same order in each folder (ie. file 1a is the first file in folder 1, and file 2a is the first in folder 2 etc.), what should I use to get the files from the folders and run them through the function?

Subject: Running a batch of pairs of files

From: Baalzamon

Date: 5 Jul, 2011 14:55:26

Message: 2 of 3

"Charles Dillon" wrote in message <iuckr8$8t1$1@newscl01ah.mathworks.com>...
> I have what I assume is a dumb question, yet I cannot find an answer to it.
> I want to write a programme to run a bunch of tests through a function and store the answers produced. Each run of the function requires two files, and each file has a pair with which it must be run. Something like:
> runfile('1a.txt', '2a.txt');
> where 1a.txt and 2a.txt are a pair of files.
> How could I get a program to run each pair of files? I assume I should first separate the two types of files into separate folders. Once I do that, and they are in the same order in each folder (ie. file 1a is the first file in folder 1, and file 2a is the first in folder 2 etc.), what should I use to get the files from the folders and run them through the function?
 
depends upon the type of file and the contents. For a formatted text file (deliminated) I use dlmread if the contents are all numbers. As my text files are basically arrays this is useful as the contents are placed into an array.

Many ways - you could pass the input file names into a cell array:

filenames = { file1a, file1b; file2a,file2b,....filena,filenb}
% Here each pair is in a new row
then use it for a loop


for file = 1: size(filenames,1)
results{file } = runfile(filenames{file,1}, filenames{file,2} )
end;

So you use your for loop to pass the required filename into runfile()

Subject: Running a batch of pairs of files

From: TideMan

Date: 5 Jul, 2011 20:06:17

Message: 3 of 3

On Jun 29, 1:27 am, "Charles Dillon" <charl...@live.ie> wrote:
> I have what I assume is a dumb question, yet I cannot find an answer to it.
> I want to write a programme to run a bunch of tests through a function and store the answers produced. Each run of the function requires two files, and each file has a pair with which it must be run. Something like:
> runfile('1a.txt', '2a.txt');
> where 1a.txt and 2a.txt are a pair of files.
> How could I get a program to run each pair of files? I assume I should first separate the two types of files into separate folders. Once I do that, and they are in the same order in each folder (ie. file 1a is the first file in folder 1, and file 2a is the first in folder 2 etc.), what should I use to get the files from the folders and run them through the function?

help dir

But beware!
The order the files are brought in to Matlab may not be the order you
want/expect, so a better way is to choose one and find the the other
matching file using strmatch or similar.

Tags for this Thread

No tags are associated with 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