organising large sets of data into a irregular matrix
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a large data sets with of 40000+ samples, which are organised in 2 columns. The first colum tells me a cluster-number (column 1) by which I would like to sort, and the second a value is a time which I would like to allocated to the individual clusters.
the data looks something like:
A=[32 7.83425
32 8.0074
5 8.01005
5 8.0119
5 8.10775
19 8.1082
7 8.1085
4 8.1089]
I would like to organise this set into a matrix or table. One caveat is that the clusters are different sizes.
I have managed to get the individual cluster number out of my matrix, using the unique function.
I thought this would be similar to this thread:
https://uk.mathworks.com/matlabcentral/answers/19877-organizing-data-into-a-matrix-generating-a-matrix
However I am struggling to assign the values to the clusters because of the irregular number of values per cluster.
Can someone help me with this?
0 个评论
采纳的回答
Jos (10584)
2019-3-7
You can use cell arrays for this.
A=[ 32 7.83425
32 8.0074
5 8.01005
5 8.0119
5 8.10775
19 8.1082
7 8.1085
4 8.1089 ]
[unA, ~, j] = unique(A(:,1)) ;
C = accumarray(j, A(:,2), [numel(unA),1], @(x) {x})
% The cell C{k} contains all values that belong to unA(k)
However, for some purposes you can also use a matlab table, for which dedicated functions, like splitapply, exist to operate on groups. This may worthy of some exploration on your site ...
4 个评论
Jos (10584)
2019-3-8
You're welcome :-)
Switching to column orientation inside the text file might not be trivial though. As you need to re-arrange the values between the cells of C.
You might also be interested in xlswrite, btw.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!