Borrar filtros
Borrar filtros

extract row from a cell

10 visualizaciones (últimos 30 días)
Alberto Acri
Alberto Acri el 17 de Jun. de 2023
Respondida: Voss el 17 de Jun. de 2023
Hi! I generated a cell similar to this one:
a = {'home'};
b = {'ball' , 'cake' , 'ice'};
c = {'car','moto'};
d = {'money','supercar','toys'};
e = cell(4,0);
e(1,1:numel(a)) = a;
e(2,1:numel(b)) = b;
e(3,1:numel(c)) = c;
e(4,1:numel(d)) = d
I want to extract from cell "e" the first row consisting of three values.
In the case above, the second row of cell "e" consists of three values, one per column. I want to extract this second row.

Respuesta aceptada

Voss
Voss el 17 de Jun. de 2023
a = {'home'};
b = {'ball' , 'cake' , 'ice'};
c = {'car','moto'};
d = {'money','supercar','toys'};
e = cell(4,0);
e(1,1:numel(a)) = a;
e(2,1:numel(b)) = b;
e(3,1:numel(c)) = c;
e(4,1:numel(d)) = d;
% construct a logical matrix the same size as e saying whether each
% corresponding cell of e is non-empty:
e_nonempty = ~cellfun(@isempty,e)
e_nonempty = 4×3 logical array
1 0 0 1 1 1 1 1 0 1 1 1
% find the first row of e that has three non-empty cells:
row = find(sum(e_nonempty,2) == 3,1)
row = 2
% extract that row of e:
result = e(row,:)
result = 1×3 cell array
{'ball'} {'cake'} {'ice'}

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by