Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Cut the last n of matrix row ?

Asked by I Made on 25 Mar 2013

e.g i have matrix a :

1

2

3

4

5

6

7

i want to cut the last 2 row of matrix A ? and become

1

2

3

4

5

0 Comments

I Made

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 25 Mar 2013
Edited by Andrei Bobrov on 25 Mar 2013
Accepted answer
a = (1:7)'; n = 2;
A = a(1:end - n);

or

a(end - [n-1, 0]) = [];

1 Comment

Jan Simon on 25 Mar 2013

The 2nd command might be:

a(end - (n-1:0)) = [];

But this would be faster (for large problems), because the vector end-n-1:end is not created explicitly:

a(end-n-1:end) = [];
Andrei Bobrov

Contact us