필터 지우기
필터 지우기

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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by