How to write several matlab variables into one struct array?

3 views (last 30 days)
Marc Hummel
Marc Hummel on 5 Apr 2016
Answered: Walter Roberson on 5 Apr 2016
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?
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} =;
% 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});

Answers (1)

Walter Roberson
Walter Roberson on 5 Apr 2016
I suggest you use one of the recursive directory File Exchange contributions.

Community Treasure Hunt

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

Start Hunting!

Translated by