How can I make a vector from a matrix?

Hi everybody,
I wanna transform an entire matrix to a vector, I need take all the columns from the first value until a previously defined value and after that concatenate into a vector to plot. For example:
A =
1 2 3
4 5 6
7 8 9
0 10 11
0 12 13
0 14 0
0 0 0
I need the answer: A= [1 4 7 2 5 8 10 12 14 3 6 9 11 13]
I know the positions where the 0's start.
Someone can help me please?
regards.

 采纳的回答

A = A(A~=0)

3 个评论

I've tried this, but in some columns I need the 0's between other numbers. For example:
A =
1 2 3
4 5 6
7 8 9
0 10 11
6 0 13
0 14 0
0 0 0
A= 1 4 7 0 6 2 5 8 10 0 14...etc.
Also, I have the position where start the first 0 value.
Regards.
Like this?:
>> A(flipud(cumsum(+flipud(A~=0),1))>0)
ans =
1
4
7
0
6
2
5
8
10
0
14
3
6
9
11
13
Like this, Tkans you very much!

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by