필터 지우기
필터 지우기

I want to extract half of the non-zero element of a matrix

조회 수: 1 (최근 30일)
BANI tita
BANI tita 2012년 10월 14일
Hello, I have a matrix of the following form: [1,0,0,0;0,0,0,0;0,10,0,12;13,0,0,0], I need a mask that allows me to extract half of the data of each nonzero matrix of this form in this case for example I want the following result [1,0,0,0;0,0,0,0;0,10,0,0;0,0,0,0]

답변 (2개)

Matt J
Matt J 2012년 10월 14일
idx=find(A);
A(idx(2:2:end))=0;

Andrei Bobrov
Andrei Bobrov 2012년 10월 14일
ii = 1:fix(nnz(A)/2);
At = A';
jj = find(At);
At(jj(fix(nnz(A)/2)+1:end)) = 0;
out = At';

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by