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
回答 (1 件)
Andrei Bobrov
2017 年 8 月 2 日
編集済み: Andrei Bobrov
2017 年 8 月 2 日
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);
カテゴリ
ヘルプ センター および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!