Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import files in Matlab

Status
Not open for further replies.

dimikay1

Civil/Environmental
Mar 30, 2013
4
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???
 
Replies continue below

Recommended for you

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.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor