How do I add to a structure in a for loop?
Show older comments
I have a bunch of matlab variable files in a directory that I want to load into one structure for analysis on later. Right now I can get the file to load into the structure but it gets replaced when the for loop starts over. It might be something simple I'm overlooking; I just don't use MATLAB often.
files = dir('*.mat');
for i=1:length(files)
S=load(files(i).name,"-mat");
end
Accepted Answer
More Answers (1)
files = dir('*.mat');
for i=1:length(files)
S{i,1}=load(files(i).name,"-mat");
end
Categories
Find more on Structures 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!