How to load a folder into Matlab?

조회 수: 59 (최근 30일)
Hope
Hope 2017년 3월 5일
답변: Image Analyst 2017년 3월 5일
For MATLAB R2016a:
I have a folder of 1,000 files. Each file is a matrix. I want to load the folder into my workspace and loop through the folder to work with each file.
I've tried:
files = dir(C:\"insert path to folder here")
and in the loop to work with each file
eval(files(i).name)
Thank you!
  댓글 수: 1
Stephen23
Stephen23 2017년 3월 5일
편집: Stephen23 2017년 3월 5일
What do you imagine that eval of a filename would achieve? Why not use any of the file import methods that are introduced and explained in the documentation (none of which use eval on a filename):
The documentation has working examples too, so beginners and experts alike can see how the functions should be used. Loading files is such a common task that it is clearly explained in many forums and wikis, e.g.:
And in future, when you are tempted to use eval for such trivial code, think again:

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2017년 3월 5일
In the middle of the loop, put your function to read in data. NOT eval() but something like csvread(), dlmread(), fileread(), importdata(), readtable(), xlsread(), imread(), or whatever.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by