Reading file name in a loop.
10 views (last 30 days)
Show older comments
Hi,
I've a Matlab-File for a specific calculation which is placed in a Folder 'A'.
Folder 'A' contains seven more Folder 'B1,B2,...,B7' with different variants. Each folder 'B1,...,B7' contains 45 excell files.
Actually I'm loading a specific excell file with this code:
addpath B1
filename = 'VAR2_D302_N100000_BP5.xlsx'
num = xlsread(filename);
and have to change every time the addpath name if I want to jump in another folder or the filename if I want to select another excell fle.
Is there any other way to do this. I mean how can I automatize this process?
I was thinking of a loop which selects the folder and excell file in need by specifying variables which output the name of my files.
% Example with two files in a Folder 'B1'
% VAR2_D302_N100000_BP5.xlsx
% VAR2_D302_N100000_BP6.xlsx
X=2;
for i=1:X
addpath B1
filename = 'VAR2_D302_N100000_BPX.xlsx' % This will not work. How can I tell matlab that the 'i' is changing?
end
num = xlsread(filename);
Thank you.
0 Comments
Answers (1)
KSSV
on 17 Nov 2017
This question is discussed to death.....A search in google and mathworks will give you lot os links.
0 Comments
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!