MATLAB: Removing duplicates in an array duplicateunique If i have the following array a =[1,1,1,2,2,1,1,6,6,6,8,8,2,2,3,3,2,2] When i do unique(a,'stable'), i get [1,2,6,8,3] I want the following result [1,2,1,6,8,2,3,2] Best Answer b = a(logical([1 (diff(a)~=0)])) Related SolutionsMATLAB: What determines the shape of a logically indexed array Just to complete the story, the answer seems to be:If B is a logical array and A is any array, then A(B) is equivalent (but faster) way to produce the same result as A(find(B)), including the shape of the output. MATLAB: Find how many times same element is repeated A=[9,8;7,6;1,2;2,4;3,4;3,4;4,7;6,7;8,6;9,8;7,6];a = unique(A,'rows');R = zeros(size(a,1),1);for k = 1:size(a,1) R(k) = nnz(ismember(A,a(k,:),'rows'));endResult = table(a,R,'VariableNames',{'Rows','Times'})Gives:Result = 8×2 table Rows Times ______ _____ 1 2 1 2 4 1 3 4 2 4 7 1 6 7 1 7 6 2 8 6 1 9 8 2 >> Related QuestionNeed to remove repeated adjacent elements in an arrayUnion of cell matrixSum two arrays using logical indicesRemoving repeated numbers in a matrixCreate a new array from an intersection of two previous arraysHow do i find all elements of value R in a matrix that are neighboring an element of value K
Best Answer