Cut the last n of matrix row ?

3 visualizzazioni (ultimi 30 giorni)
I Made
I Made il 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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 25 Mar 2013
Modificato: Andrei Bobrov il 25 Mar 2013
a = (1:7)'; n = 2;
A = a(1:end - n);
or
a(end - [n-1, 0]) = [];
  1 Commento
Jan
Jan il 25 Mar 2013
Modificato: Jan il 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) = [];

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by