Clear Filters
Clear Filters

How can to concatenate data from each column of a cell array into a row?

2 views (last 30 days)
I have a 1x13 cell array where each column has a 1200x2 array.
I need to reorganize it to a 1x15600 with a 2x1 array in each column. In other words, 1x15600 cell array of 2x1 vectors representing two values over 1200 timesteps to use as a InputSeries of a Neural Network.
Visually, I have:
c1 c2 c13 -> column of cell array
-------------------------------------------------------
1 1.2 1.3 1.4 1.25 1.26
2 2.2 2.3 2.4 2.25 2.26
3 3.3 3.3 3.4 3.25 3.26
.
.
.
1200 1200.2 1200.3 1200.4 1200.25 1200.26
What I need:
c1 c2 c1200 c1201 c1202 c15600 -> number of columns of new cell array
------------------------------------------------------------------------
1 2 1200 1.3 2.3 1200.25
1.2 2.2 1200.2 1.4 2.4 1200.26
I tried to transpose the original cell array to have a 1x13 w/2x1200 and then concatenate each column but my code never worked as I wanted. Some commands I used: transpose, cat, reshape, arrayfun.
Thank you, Erika

Accepted Answer

James Tursa
James Tursa on 26 Oct 2016
Edited: James Tursa on 26 Oct 2016
Like this?
C = your cell array
result = mat2cell(cell2mat(cellfun(@transpose,C,'uni',false)),2,ones(1,15600));

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!