필터 지우기
필터 지우기

How to write several matlab variables into one struct array?

조회 수: 1 (최근 30일)
Marc Hummel
Marc Hummel 2016년 4월 5일
답변: Walter Roberson 2016년 4월 5일
Hey every one. Im new to matlab and have a little Problem. I want to read several files from different folders and save them all into wan struct list, to use the file names later. Everything is find until the point, where to 'for'-comand jumps from the 2nd to the 3rd folder. Then the code just writes the first file name into the new struct and leaves the rest. Can anyone please help me complete my code?
Tanks
for k = 1 : numberOfFolders
% Get this folder and print it out.
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
filePattern = sprintf('%s/*.dat', thisFolder);
baseFileNames = dir([listOfFolderNames{k} '/*dat']); %filePattern);
numberOfFiles = length(baseFileNames);
if numberOfFiles >= 1
i = i+numberOfFiles;
baseFilename{i,1} = baseFileNames.name;
% Go through all those dat files.
for f = i : numberOfFiles
fullFileName {f,1} = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing dat file %s\n', fullFileName {f,1});
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 5일
I suggest you use one of the recursive directory File Exchange contributions.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by