Storing outputs of for loop within a for loop

1 vue (au cours des 30 derniers jours)
Anthony
Anthony le 5 Jan 2015
Commenté : Stephen23 le 5 Jan 2015
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 commentaires
Anthony
Anthony le 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 le 5 Jan 2015
Ive made the change and removed i/j as variables replacing them. The update is attached.
Thanks!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 5 Jan 2015
Modifié(e) : Stephen23 le 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 commentaires
Anthony
Anthony le 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.
Stephen23
Stephen23 le 5 Jan 2015
Glad to help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by