Create new array for each iteration ?

4 visualizaciones (últimos 30 días)
Mini Me
Mini Me el 17 de Abr. de 2017
Editada: Mini Me el 18 de Abr. de 2017
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 comentarios
Stephen23
Stephen23 el 18 de Abr. de 2017
@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 el 18 de Abr. de 2017
Editada: Mini Me el 18 de Abr. de 2017
@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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by