how to split a forloop into columns

조회 수: 3 (최근 30일)
A123456
A123456 2016년 1월 6일
댓글: Star Strider 2016년 1월 6일
I have written a code which contains a for loop but I need it to be seperated into columns. This is the code, however I would like each value of N to be a new column. Is there a way of doing that?
for N=1:12;
for m=1:12;
if mod(N, m)==0
disp '1'
else disp '0'
end
end
end

채택된 답변

Star Strider
Star Strider 2016년 1월 6일
I am not certain what you want to do. See if this produces what you want:
N = 1:12;
m = 1:12;
[Nmat,mmat] = meshgrid(N,m);
modmat = mod(Nmat,mmat)==0;
Result = [Nmat(:) mmat(:) modmat(:)];
  댓글 수: 8
A123456
A123456 2016년 1월 6일
Thanks for that, your help was great!
Star Strider
Star Strider 2016년 1월 6일
As always, my pleasure!

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

추가 답변 (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