How can I get a vector out of a matrix?

7 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2017-9-9
编辑:KALYAN ACHARJYA 2017-9-9
First convert Matrix to vector
%
vector=matrix(:);
%Do the Operation
result=[vector(1,2),vector(2,4),vector(1,2),vector(3,6)]
%
Stephen23
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
José-Luis 2017-9-9
Sounds like a job for sub2ind()

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by