Storing outputs of for loop within a for loop

1 次查看(过去 30 天)
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 个评论
Anthony
Anthony 2015-1-5
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 2015-1-5
Ive made the change and removed i/j as variables replacing them. The update is attached.
Thanks!

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2015-1-5
编辑:Stephen23 2015-1-5
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 个评论
Anthony
Anthony 2015-1-5
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by