Cut the last n of matrix row ?

1 Ansicht (letzte 30 Tage)
I Made
I Made am 25 Mär. 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

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 25 Mär. 2013
Bearbeitet: Andrei Bobrov am 25 Mär. 2013
a = (1:7)'; n = 2;
A = a(1:end - n);
or
a(end - [n-1, 0]) = [];
  1 Kommentar
Jan
Jan am 25 Mär. 2013
Bearbeitet: Jan am 25 Mär. 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) = [];

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by