フィルターのクリア

Storing outputs of for loop within a for loop

1 回表示 (過去 30 日間)
Anthony
Anthony 2015 年 1 月 5 日
コメント済み: Stephen23 2015 年 1 月 5 日
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.
Stephen23
Stephen23 2015 年 1 月 5 日
Glad to help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by