How to organise cell array data into a single table
Afficher commentaires plus anciens
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
Réponses (1)
Andrei Bobrov
le 2 Août 2017
Modifié(e) : Andrei Bobrov
le 2 Août 2017
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);
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!