필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
Lakyn
Lakyn 2016년 8월 23일
댓글: Walter Roberson 2016년 8월 23일
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!

채택된 답변

James Tursa
James Tursa 2016년 8월 23일
M = A(triu(true(size(A)),1));
  댓글 수: 3
James Tursa
James Tursa 2016년 8월 23일
Yep ... I didn't notice this was a repeat Question.
Walter Roberson
Walter Roberson 2016년 8월 23일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by