×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

opening multiple files in loop

opening multiple files in loop

opening multiple files in loop

(OP)
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

RE: opening multiple files in loop

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

RE: opening multiple files in loop

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

RE: opening multiple files in loop

(OP)
thanks for that guys, ended up using mikeyP's suggestion. worked first time, but will look into the eval function.
M

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now