MATLAB: Convert cell-array to array-of-cells, for array-of-struct creation

arrayarray cellarray structurecellcell arrayMATLABtextscan

Hi, how can I convert a cell-array to an array-of-cells?
I have (following a file textscan) a cell array of format:
Fr = [{uint8([1;2;3])}, {uint32([4;5;6])}, {[7;8;9]}]
And need to get to this array of cells:
To = [{Fr{1,1}(1), Fr{1,2}(1), Fr{1,3}(1)} ;...
{Fr{1,1}(2), Fr{1,2}(2), Fr{1,3}(2)} ;...
{Fr{1,1}(3), Fr{1,2}(3), Fr{1,3}(3)}]
..without having to loop (Fr can be large) through Fr.
The reason is that I want an array-of-struct, rather than struct-of-array. Reference:
Incorrect = cell2struct(Fr,{'f1','f2','f3'},2)
Correct = cell2struct(To,{'f1','f2','f3'},2)

Best Answer

Fr = [{uint8([1;2;3])}, {uint32([4;5;6])},...
{[7;8;9]}, {uint8([11,12;13,14;15,16])}];
To = cellfun(@(x)num2cell(x,2),Fr,'un',0);
out = [To{:}];