Remove values from cell array based on condition
Afficher commentaires plus anciens
Hey
I have two cell arrays like this:
A= {[2,3,4,5,6]; [1,3,4,5,6,7,8] }
B= {NaN, 1,1,-0.9,0.8,[],[]; NaN, NaN, 0.9,-1,NaN,0.8,0.2}
I want to find indexes of values less than 0 and of NaN values in B like here in first row of B we will get 1 (for NaN) and 4 for (values less than zero) and for these indexes i want to remove values placed in A like value at index 1 in A is 2 so it will be removed and also 5 will be removed. Same for row 2. New matrix A will look like this:
NewA= {[3,4,6]; [4,7,8]}
Please help.
Réponse acceptée
Plus de réponses (1)
José-Luis
le 16 Août 2017
A= {[2,3,4,5,6]; [1,3,4,5,6,7,8] }
B= {NaN, 1,1,-0.9,0.8,[],[]; NaN, NaN, 0.9,-1,NaN,0.8,0.2}
result = cell(size(A));
dummy = cellfun(@(x) ~isempty(x) && ~isnan(x) && x >= 0 ,B,'UniformOutput', false);
for ii = 1:size(A,1)
result{ii} = A{ii}([dummy{ii,:}])
end
1 commentaire
lucksBi
le 16 Août 2017
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!