making sub arrays of first column depending on the second column number

1 次查看(过去 30 天)
Hi,
I have a matrix with 2 columns let's assume [ 15 2;14 2;10 3;13 3;9 3] how can I get sub arrays from the first column that corresponds to the same number of second column. in this example [15 14] and [10 13 9]? Appreciate your help. Thanks.

采纳的回答

madhan ravi
madhan ravi 2019-7-9
Wanted = splitapply(@(x){x},a(:,1),findgroups(a(:,2))) % where a is your matrix
celldisp(Wanted)

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-7-9
G = findgroups(YourMatrix(:,2));
subarrays = splitapply(@(varargin) {varargin{:}}, YourMatrix(:,1), G);

类别

Help CenterFile Exchange 中查找有关 Word games 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by