I am new to MATLAB and was confused about how to obtain numeric arrays from cell arrays. According to MATLAB, I have some matrix result
and I get the following:
>> size(result)
ans =
1 15
>> result
ans =
Columns 1 through 15
[3] [15] [1x2 double] [13] ... \\ Omitted for clarity
>> iscell(result)
ans =
1
So it seems like result is a 2-D cell array of dimensions 1 x 15, but there is also a sub-array (?) within it, indicated by the [1x2 double]
. In this particular example, let's assume that there is only one of these [1x2 double]
elements. In other words, result
consists of fourteen single-element columns and one multi-element column.
I checked the documentation and according to this page there is a method called cell2mat
. Unfortunately it doesn't quite do what I need, because it outputs a 1x16 numeric array:
>> cell2mat(result)
ans =
3 15 10 7 13 ... \\ Omitted for clarity
In this example, 10 and 7 were the elements that composed the [1x2 double]
, it's just that MATLAB for whatever reason didn't indicate that when printing the cell array.
Question: is there a way I can convert this matrix into a numeric array of arrays while preserving the grouping? Specifically, I'm hoping to get something of the form [[3], [15], [10, 7], [13], ...] and have these be numeric. Is this possible? For what it's worth, I'm using MATLAB with some Java code from matlabcontrol, and that software appears to require real-valued arrays-of-arrays.