MATLAB: Find order of increasing integers integerssorting I have a vector [3,4,8,9,10,13] How can I sort this into [3,4]; [8,9,10]; [13]; in an efficient way? I.e., split the parts of the vector where there is a linear increase of +1 from the previous entry. Best Answer V = [3,4,8,9,10,13];D = diff(find([true,diff(V)~=1,true]));C = mat2cell(V,1,D)C = 1×3 cell array {[3 4]} {[8 9 10]} {[13]} Related SolutionsMATLAB: Finding the increase in values a = [2;2;2;3;3;3;5;5;5;4;4;3;3;3;2;2;3;3;3;4;4;4;5;5;5;4;4;3;3]idx = [true;diff(a)~=0];idy = diff(a(idx))>0;idd = diff([0;idy;0]);idb = find(idd>0);ide = find(idd<0);ids = cumsum(idx);fun = @(b,e)a(ismember(ids,b:e));C = arrayfun(fun,idb,ide,'uni',0);And checking the output:>> C{:}ans = 2 2 2 3 3 3 5 5 5ans = 2 2 3 3 3 4 4 4 5 5 5 MATLAB: How to quickly find the index of each integer in an ascend array Use the unique function: A = [1 1 1 1 1 2 2 3 3 3 3 3 4 4 4 5 5 5 5 6 7 7 7 8 8];[Au,firstidx] = unique(A(:), 'stable');Result = [Au, firstidx]producing: Result = 1 1 2 6 3 8 4 13 5 16 6 20 7 21 8 24 Related QuestionCheck for decrease and increaseHow to find locations of multiple values within a matrix.Regarding Increase ResolutionSplitting vectors into cell array in a loopIncreasing xcorr() resolution
Best Answer