필터 지우기
필터 지우기

How to store all loop results? how can i solve this problem??

조회 수: 1 (최근 30일)
arkedia
arkedia 2014년 12월 21일
댓글: Stephen23 2014년 12월 22일
i have the following loop
for i=1:4
for j=2:5
if i<j
a=i;
b=j;
ind=[a,b]
end
end
end
how can i store all results for example: a=
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
  댓글 수: 1
Stephen23
Stephen23 2014년 12월 22일
Don't do this in a loop: see Jan Simon's much improved solution to this problem.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 21일
편집: Azzi Abdelmalek 2014년 12월 21일
k=0;
for i=1:4
for j=2:5
if i<j
k=k+1;
ind(k,1:2)=[i,j]
end
end
end
%or
[a,b]=meshgrid(1:4,2:5);
c=[a(:) b(:)];
out=c(diff(c,[],2)>0,:)

추가 답변 (1개)

Jan
Jan 2014년 12월 21일
What about:
nchoosek(1:5, 2)

카테고리

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