How can I get a vector out of a matrix?

조회 수: 1 (최근 30일)
Shang Gao
Shang Gao . 2017년 9월 9일
편집: Stephen23 . 2017년 9월 9일
Given a two dimension matrix, if I want to extract 3 elements with subsript (1,2) (2,4) (3,6) to form a vector, how I can I achieve that without using a double loop? Because if I just use M(1:3,2:2:6), the result will also be a matrix. Can someone give me a simple solution?
  댓글 수: 2
Stephen23 2017년 9월 9일
편집: Stephen23 님. 2017년 9월 9일
@KALYAN ACHARJYA: a column vector has no columns 2, 4, or 6.
One good way is to use sub2ind, as José-Luis has already answered.

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

답변 (1개)

José-Luis 2017년 9월 9일
Sounds like a job for sub2ind()


Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by