Borrar filtros
Borrar filtros

How to remove cells in cell matrix that are a certain value?

2 visualizaciones (últimos 30 días)
Dc215905
Dc215905 el 18 de Jun. de 2021
Editada: Rik el 19 de Jun. de 2021
Hello,
I have a 8x4 cell matrix that looks like:
1x761200 double 1x121400 double 1x299600 double 1x555000 double
1x761200 double 1x121400 double 1x299600 double 1x555000 double
1x761200 double 1x121400 double 1x299600 double 1x555000 double
1x761200 double 1x121400 double 1x299600 double 1x555000 double
-1 -1 -1 -1
-1 -1 -1 -1
1x761200 double 1x121400 double 1x299600 double 1x555000 double
1x761200 double 1x121400 double 1x299600 double 1x555000 double
I would like to find which rows contain '-1' and then remove those rows from the matrix.
Any suggestions?

Respuesta aceptada

Rik
Rik el 18 de Jun. de 2021
Editada: Rik el 19 de Jun. de 2021
data(all(cellfun('prodofsize',data)==1),:)=[];
You might need to specify the dimension for the all function (writing of mobile, so no testing). You might also mean the any function instead of all.
Edit:
This does indeed require a modification:
L=all(cellfun('prodofsize',data)==1,2)
% ^^
data(L,:)=[]
  3 comentarios
Rik
Rik el 18 de Jun. de 2021
Let's try with a simple example (and the dimension changed, I really should learn the syntax some day..).
data={...
[1 2],[1 2],[1 2];...
-1 ,-1 ,1 ;...
[1 2],[1 2],[1 2]};
L=all(cellfun('prodofsize',data)==1,2)
L = 3×1 logical array
0 1 0
data(L,:)=[]
data = 2×3 cell array
{[1 2]} {[1 2]} {[1 2]} {[1 2]} {[1 2]} {[1 2]}
Dc215905
Dc215905 el 19 de Jun. de 2021
Thank you! That works great!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by