Accessing 1 by n array from a cell array

1 view (last 30 days)
The output of the following code is the cell array poh. Is there a way to instead access the first subarray {'poh',3,4.56} through a similar command and commands to find, for example, its size?

Accepted Answer

Star Strider
Star Strider on 12 Oct 2020
Edited: Star Strider on 12 Oct 2020
The problem is that the square brackets [] concatenate the two cells to produce:
a =
1×5 cell array
{'poh'} {[3.0000e+000]} {[4.5600e+000]} {'v'} {[5.0000e+000]}
If you replace them with curly braces {}, ‘a’ becomes:
a =
1×2 cell array
{1×3 cell} {1×2 cell}
and the result of
ans =
1×3 cell array
{'poh'} {[3.0000e+000]} {[4.5600e+000]}
as desired.
With that, you can then get:
Out = cellfun(@size, a, 'Uni',0)
ans =
1 3
ans =
1 2
EDIT — (12 Oct 2020 at 13:23)
Added example results.

More Answers (0)


Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!