Is there a way to concat to a cell array and not have a vertical cell array?

1 view (last 30 days)
I'm trying to concat to a cell array that is 1:x. When I use the methods here...
https://www.mathworks.com/matlabcentral/newsreader/view_thread/105530
The concat creates a new cell array that is vertical. Is there any way to do this without it becoming vertical?
For example, if I have the cell array...
{{},{[1,2]}}
And I like to concat [2,3] to it, the result I want is...
{[2,3],{[2,3],[1,2]}}
Instead I'm getting...
{[2,3];{[2,3],[1,2]}}
Where the semicolon represents the 2x1 cell array instead of it staying as 1x2

Accepted Answer

Matt J
Matt J on 21 Jul 2017
C={{},{[1,2]}}; %example
result=cellfun(@(c)horzcat({[2,3]},c{:}),C,'uni',0)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!