Reading file name in a loop.

10 visualizaciones (últimos 30 días)
Alexander Hummel
Alexander Hummel el 17 de Nov. de 2017
Editada: Alexander Hummel el 17 de Nov. de 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.

Respuestas (1)

KSSV
KSSV el 17 de Nov. de 2017

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by