How to write several matlab variables into one struct array?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2016-4-5
I suggest you use one of the recursive directory File Exchange contributions.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!