create a vector without for
조회 수: 6 (최근 30일)
이전 댓글 표시
The vector structure is like [a b c d e f g h i j]
a=1:10
b=1:10
...
j=1:5
vect=[]
I can use for a =1:10
for b=1:10
...
vect = [vect;a.b...j]
end
end
but it looks not elegant. Is there a better way to generate it?
댓글 수: 8
Stephen23
2020년 1월 19일
"I'd like to have possible permutation"
Then you should have asked about generating permutations: http://xyproblem.info/
채택된 답변
Walter Roberson
2020년 1월 19일
a=1:10;
b=1:10;
c=1:3;
d=1:5;
[A, B, C, D] = ndgrid(uint8(a), uint8(b), uint8(c), uint8(d)) ;
v = [A(:), B(:), C(:), D(:)] ;
댓글 수: 0
추가 답변 (1개)
Image Analyst
2020년 1월 19일
Try
a = 1 : 10
b = 1 : 10
...
j = 1 : 5
outputVector = [a, b, c, d, e, f, g, h, i, j]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!