Reading file name in a loop.

조회 수: 10 (최근 30일)
Alexander Hummel
Alexander Hummel 2017년 11월 17일
편집: Alexander Hummel 2017년 11월 17일
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.

답변 (1개)

KSSV
KSSV 2017년 11월 17일

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by