Create new array for each iteration ?

조회 수: 4 (최근 30일)
Mini Me
Mini Me 2017년 4월 17일
편집: Mini Me 2017년 4월 18일
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
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:
Mini Me
Mini Me 2017년 4월 18일
편집: Mini Me 2017년 4월 18일
@jan Simon 1st and second iteration of the outer loop. I do not want to overwrite the file at all. At each iteration of the outer loop, it should append everything generated in the inner loop by rows. Then when it goes to the next iteration of the outer loop it should append the next set of results if the inner loop in the next column. For example.
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by