Create new array for each iteration ?
조회 수: 4 (최근 30일)
이전 댓글 표시
Ok so I have a nested for loop that goes like this:
for i=1:size(L,2) ----L is vector(1:1:7)
filename = ['file_',num2str(L(i))]
filename1 = 'Total result';
Array1 =[]
for j=1:size(M,1)-----M is a vector (3:1:9)
C= do some calculation
Array1 = [Array1;C]
csvwrite(filename,Array1)
end
end
I want to be able to take the values of the array1 for the first iteration and second iteration and add them to get sum of total value. Take the total values and feed it in a new array. I can't seem to get my head around that. Also I want to be able to write the values of Array 1 in each iteration of i and the total values into one csv file. Right now my first and second iteration write to different file purposely. Can you help me and point me in the right direction,please? The most important thing is to actually get the array1 at first iteration then the second array1 at 2nd iteration and add them up once the loop is done. I want the results to be written in the file like this after all the calculation has been done.
Outer loop 1 - Outer loop 2 - Total
Inner loop 1 - Inner loop 2 - inner Loop1 + inner loop 2
Inner loop 1 - inner loop 2
Inner loop 1 - inner loop 2
Inner loop 1 - inner loop 2
댓글 수: 3
Stephen23
2017년 4월 18일
@Mini Me: it is not clear what you are trying to achieve. Whatever you do, do NOT try to access lots of arrays in a loop:
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!