Concatenate Cell array of doubles along rows

i have a cell array that looks like the following (4X2) in attached image
I want to concatenate adjacent values in rows

 Accepted Answer

arrayfun(@(COLIDX) vertcat(YourCell{:,COLIDX}), 1:size(YourCell,2), 'Uniform', 0)

4 Comments

Running down the columns is the only approach that makes sense. You cannot concatenate along rows because the first cell is 9759 x 1 and the second is 9758 x 1 and it is not possible to create a matrix with two columns one 9759 long and the other 9758 long.
Or is the idea to create a cell vector, each entry of which is a cell of two columns? If so then
arrayfun(@(ROWIDX) {YourCell{ROWIDX,:}}, (1:size(YourCell,1)).', 'Uniform', 0)
the second approach is ok but can we combine them after your cell vector, maybe taking each row and transponse as a column then concatenate the vectors together
arrayfun(@(ROWIDX) vertcat(YourCell{ROWIDX,:}), (1:size(YourCell,1)).', 'Uniform', 0)
One more thing Mr. Walter to enhance the below function to incoprate your current answer, given that (please look at attached images in zip file)
function CombinedCurves= PrepareCombineCurvesCells(CurvesCell,selectedCurves,currWellNames)
fnames=fieldnames(CurvesCell);
n=cell(numel(selectedCurves)*numel(currWellNames),1);
for cWCurve=1:numel(selectedCurves)
for currWell=1:numel(fnames)
n{cWCurve,currWell}= CurvesCell.(fnames{currWell}).(selectedCurves{cWCurve});
end
end
CombinedCurves=n ;
end

Sign in to comment.

More Answers (1)

Let C be your cell array..
iwant{1} = [C{1,1} C{2,1}] ;
iwant{2} = [C{1,2} C{2,2}] ;

2 Comments

Thanks KSSV but my case is dynamic case so items might increase ,or decrease i cannot hard code indices like this
You can put that into loop....not a big deal.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!