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

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개)

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';

카테고리

도움말 센터File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

질문:

2012년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by