how to convert matrix subscript range to vector

I have a matrix range on subscript format, for example something like
y = [1:3]
x = [4:6]
I would like to convert this range to a vector containing all the elements of the range separately. I.e. the example above would result in a vector that is
v = [1,4
1,5
1,6
2,4
2,5
2,6
3,4
3,5
3,6]
Is there any nice way of achieving this, or do I have to resort to nestled for loops?

 채택된 답변

John D'Errico
John D'Errico 2017년 11월 28일

1 개 추천

help meshgrid
[xx,yy] = meshgrid(1:3,4:6);
v = [xx(:),yy(:)];

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2017년 11월 28일

댓글:

2017년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by