Azzera filtri
Azzera filtri

find zero and nonzero elemnt in cell

9 visualizzazioni (ultimi 30 giorni)
NA
NA il 29 Mag 2019
Commentato: Akira Agata il 29 Mag 2019
A={[21],[0],[32],[4],[60],[0],[0]};
B=A;
temp=cell2mat(A);
temp_1=find(temp==0);
B=cellfun(@(m,y) y(m)==0.1,temp_1,A, 'UniformOutput', false); % put 0.1 for zero element in A
temp_2=find(temp~=0);
B=cellfun(@(m,y) y(m)==0.2,temp_2,A, 'UniformOutput', false); % put 0.2 for nonzero element in A
result should be
result={[0,2],[0.1],[0.2],[0.2],[0.2],[0.1],[0.1]};

Risposta accettata

KSSV
KSSV il 29 Mag 2019
A={[21],[0],[32],[4],[60],[0],[0]};
B=A;
idx = cellfun(@any,A) ;
B(idx) = {0.2} ;
B(~idx) = {0.1} ;
  1 Commento
Akira Agata
Akira Agata il 29 Mag 2019
Another possible way:
A = {[21],[0],[32],[4],[60],[0],[0]};
B = A;
idx = cell2mat(B) == 0;
B(idx) = {0.1};
B(~idx) = {0.2};

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by