Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
BANI tita
BANI tita am 14 Okt. 2012
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]

Antworten (2)

Matt J
Matt J am 14 Okt. 2012
idx=find(A);
A(idx(2:2:end))=0;

Andrei Bobrov
Andrei Bobrov am 14 Okt. 2012
ii = 1:fix(nnz(A)/2);
At = A';
jj = find(At);
At(jj(fix(nnz(A)/2)+1:end)) = 0;
out = At';

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by