Reading file name in a loop.

9 vues (au cours des 30 derniers jours)
Alexander Hummel
Alexander Hummel le 17 Nov 2017
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.

Réponses (1)

KSSV
KSSV le 17 Nov 2017

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by