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

Import files in Matlab

Import files in Matlab

Import files in Matlab

My question is pretty simple however I haven't figured out yet.

So, I have a folder with 10,000 data files (*.dat) and I try to import them using a code because it is obvious I cannot import them one by one.

In that case the names of the files are in the form "filename_number"

The files' number should be the key in order to import them using a loop.

I used the function A=importdata('filename') to import one file. However, I need a loop in order to import all of them at once so as to create a vector of the one column I need from each file!

Any help???

RE: Import files in Matlab

Your idea will work using eval to execute a string after building the string with str2num and cell2str and char and similar functions, or you can create an array of all the filenames in the directory and step through that.

The second method is less disgusting (ie less likely to turn your computer into a smoking ruin) but the eval approach is more in the spirit of your question, and you will learn more about the difference between cell arrays and strings.


Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

RE: Import files in Matlab

oh! Thank you very much! I was trying to use the first approach but I had some difficulties!

The second approach looks great! I will try to implement it!

Another thing is that I have problem to load files from a directory different from the "documents" folder of matlab. When I use this location, the process works fine. However, I use a computer in the University and we are not allowed to paste more than 300-350 files in the matlab directory.

In that case, is there any way I can import my files from a different directory?

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


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close