How to organise cell array data into a single table

I have a 50x1 cell array (document attached) where each cell is a double array organised as follows: (T, Xi, Yi), where T is time, and Xi and Yi are coordinates of points in cell ix1. I want to organise all these data into a single table where T is in the first column, and the coordinate Xi and Yi are successively organised in the next columns. It would eventually look like that (T, X1, Y1, X2, Y2..., Xn, Yn). Any idea what I could try ? Thanks. Coz

Answers (1)

N = ["X";"Y"] + string(1:numel(coordinates));
k = N(:)';
k = [{'T'},{k{:}}];
n = cellfun('size',coordinates,1);
[m,id] = max(n);
Gcell = num2cell(cell2mat([{coordinates{id}(:,1)},...
cellfun(@(x,y)[x(:,2:3);nan(m - y,2)],coordinates(:)',...
num2cell(n(:)'),'un',0)]),1);
T = table(Gcell{:},'v',k);

Categories

Asked:

Coz
on 1 Aug 2017

Edited:

on 2 Aug 2017

Community Treasure Hunt

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

Start Hunting!