Storing outputs of for loop within a for loop

1 view (last 30 days)
Thanks in advance for any help that you can provide.
I am making a program to process some data and have a for loop within a for loop. I currently have the program saving some of the data from the first (outter) for loop within a vector and am doing the same with the inner for loop (the data for the outer loop is being stored as final.variable(i,:)=variable, the inner loop is doing the same but as AllThirtySecondBouts.variable(t,:)=variable). The inner loop is only able to save the data from the last iteration of the outer for loop. I am wondering if there is a way to save the data of each iteration of the inner for each outer for loop.
I have attached a copy of my code if this doesn't fully make sense. The outer for loop starts at line 49 and the inner one starts at line 311.
Thanks,
Anthony.
  5 Comments
Anthony
Anthony on 5 Jan 2015
Thanks for the quick responses. Here is the attached file.
So change i/j to other variables, but that won't fix the problem will it?
Thanks,
Anthony
Anthony
Anthony on 5 Jan 2015
Ive made the change and removed i/j as variables replacing them. The update is attached.
Thanks!

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 5 Jan 2015
Edited: Stephen23 on 5 Jan 2015
That is quite... interesting code, with all of those "chunks". But to the topic of your question: you are storing your data in structures . One thing that is not immediately obvious with structures is that they are also an array , and this means that they can have any size, not just scalar. In particular this page might be useful to you:
You can simply place your data in the structure, exactly as you are doing now, plus the addition of some indices to enlarge the structure array. Here is some simple code that illustrates this:
for m = 1:5
for n = 1:3
A(m,n).value = sprintf('m=%d n=%d',m,n);
end
end
  3 Comments
Anthony
Anthony on 5 Jan 2015
Thanks again for the help, it worked! I have attached an updated version of the program that works for anyone that might be interested.
Anthony.

Sign in to comment.

More Answers (0)

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!