Filter löschen
Filter löschen

extract row from a cell

10 Ansichten (letzte 30 Tage)
Alberto Acri
Alberto Acri am 17 Jun. 2023
Beantwortet: Voss am 17 Jun. 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.

Akzeptierte Antwort

Voss
Voss am 17 Jun. 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'}

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by