MATLAB: After using triu, how to exclude the 0s in the vector

matrixtriuvector array

Hi all, So my matrix, lets call it A is 76×76, 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!

Best Answer

M = A(triu(true(size(A)),1));