Unable to open file with Importdata after dir with subfolders?

조회 수: 2 (최근 30일)
JM
JM 2019년 2월 4일
댓글: Walter Roberson 2019년 2월 4일
I've used this simple code before with all of my files in one folder and it worked fine.
However I've modified it by adding ** because I now want to get all of the files in subfolders.
The first part of the code seems to be working, it creates a structure from dir with all of my files.
The problem is the second part does not seem to be working as it normally does. I am receiving the erorr message
"Error using importdata (line 137)
Unable to open file."
I'm guessing there is a modification I need to make because I am now using dir with subfolders, but I'm lost as to what change needs to be made.
My goal is to identify all of the files with a specific name, and store the data from those files in variables.
Thank you.
Eyefiles = dir('**\*SMI*')
Vivefiles = dir('**\*Euler*')
%%
for k = 1:length(Eyefiles)
eyedata{k} = importdata((Eyefiles(k).name))
end
for b = 1:length(Vivefiles)
vivedata{b} = importdata((Vivefiles(b).name))
end

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 4일
fullfile(Eyefiles(i).folder, Eyefiles(i).name)
to construct the file name
  댓글 수: 3
JM
JM 2019년 2월 4일
Hey Walter,
After running the code successfully with your suggestion, I did notice one weird outcome and I'm not sure why it is happening.
The code works, but on certain iterations of the loop, it seems to actually put more than 1 files worth of data in a given column. So if each column is supposed to contain a 1x30 structure from excel, randomly it seems that some columns will have 1x60, 1x120, etc as if there is extra files being stored.
Hope I am describing it OK. Not sure if this is just a matlab glitch or what, because for a majority of the files it runs fine and puts the appropriate data in.
Walter Roberson
Walter Roberson 2019년 2월 4일
I am not sure off-hand, but I would suggest experimenting with readtable()
Would your files happen to be .xls or .xlsx ? If so I wonder if some of them have multiple sheets?

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

추가 답변 (0개)

카테고리

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