Storing for loop nested value in a vector

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!

 채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 12일
편집: Walter Roberson 2017년 11월 12일

1 개 추천

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

Kundera
Kundera 2017년 11월 12일
Thanks, exactely what I needed.
alice
alice 2020년 3월 26일
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.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 11월 12일

댓글:

2020년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by