MATLAB: Group a Array Elements group a array elements X=[1 2 3 3 3 1] index 1 -> 1 index 2 -> 2 index 3 -> 3 index 4 -> 3 index 5 -> 5 index 6 -> 1 y=[{1,6},{2},{3,4,5}] How create matrix y? Best Answer X=[1 2 3 3 3 1] ;[c,ia,ib] = unique(X) ;iwant = cell(length(c),1) ;for i = 1:length(c) iwant{i} = find(ib==i) ; iwant{i}end Related SolutionsMATLAB: How to create the array [1, 2,2 ,3, 3, 3, 4,4 4, 4] >> V = 1:10;>> floor(sqrt(2*V)+1/2)ans = 1 2 2 3 3 3 4 4 4 4 MATLAB: How can i extract and store colums from the data data = importdata('data.txt') ;id = data(:,1) ; [c,ia,ib] = unique(id) ;N = length(c) ; iwant = cell(N,1) ; for i = 1:N iwant{i} = data(ib==i,:) ; end Related QuestionFind element index of one array which is equal to the values from another arrayAuto split matrix into other matrices (up to n)How to replace half the number of specific element in an arrayFind edges in a plot
Best Answer