triangle matrix with different number of columns

how to make a triangle matrix, from a matrix example like this
a =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
and the matrix that i'm looking for will like this a =
35 1 6 26 19 24
0 32 7 21 23 0
0 0 2 22 0 0
Thanks, Rio

2 commentaires

Your result is not a matrix
oke edited, can you help me now?

Connectez-vous pour commenter.

 Réponse acceptée

Use triu (or tril to get triangular matrices. Use flipr on the matrix and on the output, if you want to apply them antidiagonally (which is an odd thing to want):
a = [ 35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11];
out = fliplr(triu(fliplr(triu(a(1:3, :)))))

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by