Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

opening multiple files in loop 1

Status
Not open for further replies.

bigmike500

Mechanical
Oct 12, 2004
6
0
0
GB
i am wondering if anyone can help me with my problem i am trying to open multiple dat files that contant different values from a measurement device. these come in the form 1,2,3...N etc. i want to make a for loop that will open one of these files do some processing on the data in it then output a singular value. the data processing i am fine with, the problem i am having is opening the file in a loop. this is the code i am using in the loop but due to the comma's matlab looks for the file N, can i get matlab to look for the file of value N.

fopen('N.dat')

so what i want to do is have N the loop counter and open the file 1, do some processing on that then close it and finish the loop, then go onto file 2 etc etc.
hope it is clear what i am trying to do and would appriciate any help that people can give me.
Cheers
M
 
Replies continue below

Recommended for you

BigMike,

look at the "eval" function, not very simple to understand, but once you knoe how to use it a marvel.

The code will look like
Code:
eval(['fopen(''',num2str(k),'.dat'')'])

tompouce
 
Although the eval function is a useful thing to be aware of, it is not actually required in this instance. You can simply concatenate the string inside the function using square brackets:
Code:
fopen([int2str(k) '.dat']);
M

--
Dr Michael F Platten
 
Status
Not open for further replies.
Back
Top