How to number permutation values in "for" loop to be sequentially printed as 1, 2, 3 etc?

조회 수: 7 (최근 30일)
Hi. I have
a = [1 2 3]
b = [1 2 3]
c = [1 2 3]
I am running for loop for i = 1:3, j= 1:3 and m = 1:3. I need to print the output in terms of 1, 2, 3, 4, etc, instead of 111, 112, 113, 114, etc.

채택된 답변

Stephen23
Stephen23 2018년 6월 20일
편집: Stephen23 2018년 6월 20일
cnt = 0;
for ii = 1:3
for jj = 1:3
for kk = 1:3
cnt = cnt+1
...
end
end
end
  댓글 수: 3
Stephen23
Stephen23 2018년 6월 20일
for ii = 1:3
for jj = 1:3
for kk = 1:3
k = (ii-1)*3*3 + (jj-1)*3 + kk
...
end
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by