Borrar filtros
Borrar filtros

After using triu, how do I exclude the 0s in the vector?

6 visualizaciones (últimos 30 días)
Lakyn
Lakyn el 23 de Ag. de 2016
Comentada: Walter Roberson el 23 de Ag. de 2016
Hi all, So my matrix, lets call it A is 76x76, and I only want the top triangular corner(without the main diagonal line). I managed to get everything right, but the numbers that I don't want (lower triangle) still appears as 0, how do I remove it? My code is as below.
function M = vector2(A)
B = triu(A,1)
M = reshape(B, [] ,1)
This makes my matrix into a vector which is what I want, but there are still 0s in place of the numbers that I don't want, when I want it to just disappear completely. Please help.
Thank you very much!

Respuesta aceptada

James Tursa
James Tursa el 23 de Ag. de 2016
M = A(triu(true(size(A)),1));
  3 comentarios
James Tursa
James Tursa el 23 de Ag. de 2016
Yep ... I didn't notice this was a repeat Question.
Walter Roberson
Walter Roberson el 23 de Ag. de 2016
And I had already given that solution a couple of days ago when I listed off three ways of extracting the outputs from the pairwise averages for a previous question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by