Select values from cell array with condition using cellfun

Hi..
I need help for selecting values in cell array
for example i have this cell array:
A = {[1,1,2; 2,2,3],[1,3,4; 3,2,4],[4,3,2;-2,-3,1];[1,2,5; 2,9,8],[1,1,4; 3,8,9],[1,8,4;-6,-9,5];[1,2,3; 4,3,1],[1,4,4; 2,5,3],[1,3,2;-9,6,7]};
Then, i want to select the value that doesn't have number more than 5 and more than -5
expected result:
result = {[1,1,2;2,2,3];[1,3,4;3,2,4];[1,2,3;4,3,1];[1,4,4;2,5,3];[4,3,2;-2,-3,1]}
the code that i have tried only can select value of the condition
T = cellfun(@(n) any(any(n > 5 | n < -5)), A, 'UniformOutput', true);
Res = A(T);
Res = {[1,2,5;2,9,8];[1,1,4;3,8,9];[1,8,4;-6,-9,5];[1,3,2;-9,6,7]}
Any idea how to solve it ?
Thanks in Advance..

 Respuesta aceptada

Bhaskar R
Bhaskar R el 19 de Feb. de 2020
Editada: Bhaskar R el 19 de Feb. de 2020
Res = A(find(~cellfun(@(x)any(x>5 | x<-5, 'all'), A)));

5 comentarios

the result is still same with my code..
you can see my expected result.. thats what im looking for..
Sorry i forgot to convert 0 to 1, now corrected :-)
ooh... it only add this "~"
i didn't know about this symbol before..
so, this symbol is like a opposite value ?
do you have any documentation or reference about this symbol ? i would like to know where it can be used into..
Thank you so much
Thank you

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 19 de Feb. de 2020
Editada: madhan ravi el 19 de Feb. de 2020
A(cellfun(@(x) all(all(x>-6 & x<6)), A)) % for versions 2018b>= usage of all() would be all(...,[1,2])

Categorías

Etiquetas

Preguntada:

el 19 de Feb. de 2020

Comentada:

el 19 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by