Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
arkedia
arkedia el 21 de Dic. de 2014
Comentada: Stephen23 el 22 de Dic. de 2014
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 comentario
Stephen23
Stephen23 el 22 de Dic. de 2014
Don't do this in a loop: see Jan Simon's much improved solution to this problem.

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 21 de Dic. de 2014
Editada: Azzi Abdelmalek el 21 de Dic. de 2014
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,:)

Más respuestas (1)

Jan
Jan el 21 de Dic. de 2014
What about:
nchoosek(1:5, 2)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by