I have a hypothetical matrix say a =
1 2 3
2 4 5
3 5 6
in one command, how I can stack the first two columns vertically to have a=[1 2 3 2 4 5]'

댓글 수: 3

I got it I may use linear index so the answer is a(1:6)'
You could make this an answer (rather than a comment on the question).
I left it as a comment because i am not quite satisfied with this answer, I leave the space to some one give me a more generic answer fit any dimension

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

 채택된 답변

Guillaume
Guillaume 2018년 6월 14일
편집: Guillaume 2018년 6월 14일

1 개 추천

As you've figured out for a 3xN matrix, a(1:6)' would work. For an arbitrary sized MxN matrix:
reshape(a(:, 1:2), [], 1)

댓글 수: 1

thanks, this is the answer I was looking for, because the above one is very simple hypothetical example my main code is in terms of large dimension and i did try the reshape command but i failed many time

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

추가 답변 (0개)

카테고리

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

태그

질문:

2018년 6월 14일

댓글:

2018년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by