Storing for loop nested value in a vector

8 visualizaciones (últimos 30 días)
Kundera
Kundera el 12 de Nov. de 2017
Comentada: alice el 26 de Mzo. de 2020
Hi, I have the following nested for loop:
for i=0:3
for ii=0:3
for iii=0:3
f = (i/2) + (ii/3) + (iii/4);
end
end
end
I would like to save all the output f in a vector that would store all the output. How can I do that? Thanks!

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Nov. de 2017
Editada: Walter Roberson el 12 de Nov. de 2017
f = zeros(4,4,4);
for i=0:3
for ii=0:3
for iii=0:3
f(iii+1,ii+1,i+1) = (i/2) + (ii/3) + (iii/4);
end
end
end
f = f(:);
  2 comentarios
Kundera
Kundera el 12 de Nov. de 2017
Thanks, exactely what I needed.
alice
alice el 26 de Mzo. de 2020
I am also working with nested loops and have a similar code structure. Wondering how to get a table of the indices i,ii,iii and f.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by