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.

 Accepted Answer

Stephen23
Stephen23 on 29 May 2018
Edited: Stephen23 on 29 May 2018
A = A(A~=0)

3 Comments

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!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2015a

Community Treasure Hunt

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

Start Hunting!