Can an entire structure be iterated in a loop?

3 views (last 30 days)
I have a function that outputs a structure. I need to run this function through a series of iterations. Is it possible to iterate the entire output structure as shown below? I would like to save the structure after running through the loop as well. The code operates as follows:
for a = 1:100
for b = 1:100
% input changes per iteration
structure(a,b) = function(input);
end
end
save('path\to\destination\folder','-struct','structure');

Accepted Answer

Image Analyst
Image Analyst on 21 Jul 2017
Edited: Image Analyst on 21 Jul 2017
Looks right to me, assuming you aren't actually using the exact names function, input, and structure. You shouldn't need the '-struct' option in save though. Did you try it and have a problem?
  1 Comment
Zachary Pinz
Zachary Pinz on 21 Jul 2017
I whipped up a test scenario just now with a simpler function. I'm not calling anything by the exact names used, I just chose those for brevity. No problems, was just unsure whether it would work or not. I'm new to using structures.

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!