MATLAB Answers


How can I get a vector out of a matrix?

Asked by Shang Gao on 9 Sep 2017
Latest activity Edited by Stephen Cobeldick on 9 Sep 2017
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?


First convert Matrix to vector
%Do the Operation
@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.

Sign in to comment.

1 Answer

Answer by José-Luis
on 9 Sep 2017

Sounds like a job for sub2ind()


Sign in to comment.