Removing elements from a cell array

19 visualizaciones (últimos 30 días)
ozgur
ozgur el 25 de Feb. de 2015
Comentada: ozgur el 25 de Feb. de 2015
this is the cell array i am working on it.
intpop =
{3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell}
{3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell}
{3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell} {3x10 cell}
{3x10 cell} {3x9 cell} {3x9 cell} {3x10 cell} {3x10 cell}
{3x10 cell} {3x10 cell} {3x9 cell} {3x10 cell} {3x10 cell}
this is one of its elements.
intpop{4,1}=
[1] [5] [7] [4] [2] [1] [] [] [] []
[1] [5] [6] [2] [4] [7] [3] [5] [1] [1]
[3] [7] [2] [5] [4] [6] [1] [2] [4] [3]
What i want is: Remove the one element and other elements move left so empty element will appear at the end. For example:
I want to remove second row third column element=[6]. All other elements move left one cell so empty cell will be at the end.
This is the resulting array
intpop{4,1}=
[1] [5] [7] [4] [2] [1] [] [] [] []
[1] [5] [2] [4] [7] [3] [5] [1] [1] []
[3] [7] [2] [5] [4] [6] [1] [2] [4] [3]
  1 comentario
Jos (10584)
Jos (10584) el 25 de Feb. de 2015
Editada: Jos (10584) el 25 de Feb. de 2015
I do not get this: "Remove the one element". Can you clarify?
My suggestion: write a function that takes a single cell (like intpop{4,1}) that does what you're after
function OUT = my function(IN)
OUT = IN ;
OUT{4,1} = 'test' ;
and then call this function for every cell of intpop using CELLFUN
Y = cellfun(@myfunction, intpop)

Iniciar sesión para comentar.

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 25 de Feb. de 2015
Hi,
something like this?
intpop{4,1}(2,:) = [intpop{4,1}(2, setdiff(1:size(intpop{4,1},2), 3)) {[]}]
Titus

Más respuestas (0)

Categorías

Más información sobre Cell Arrays 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