To combine a cell array and a numeric array into a single cell array, use the num2cell
function on the numeric array and concatenate it with the original cell array using the {}
concatenation operator. Here's an example:
main.m60 chars4 lines
Output:
main.m67 chars6 lines
In this example, the num2cell
function converts the array B
into a cell array of the same size, which is then concatenated with A
using the {}
operator. The resulting array C
is a 1x5 cell array containing the elements of A
followed by the elements of B
as individual cells.
Note that the cell and the numeric arrays must have the same number of elements in this case. If they don't, you may need to adjust the size or shape of one or both arrays to ensure they can be combined without errors.
gistlibby LogSnag