How to organise cell array data into a single table
Mostrar comentarios más antiguos
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
Respuestas (1)
Andrei Bobrov
el 2 de Ag. de 2017
Editada: Andrei Bobrov
el 2 de Ag. de 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);
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!