Clear Filters
Clear Filters

How to write several matlab variables into one struct array?

1 view (last 30 days)
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

Answers (1)

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

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!