MATLAB: How to count the number of vector elements without repetition countrepetition Hi, I have a vector that contains repeated elements, How can I count the number of vector elements without repetition? For example: a=[2 5 2 8 9 8 7 8 1]; I expect the result will be: count = 6 Best Answer >> na=[2 5 2 8 9 8 7 8 1];>> length(unique(na))ans = 6>> Related SolutionsMATLAB: Help with creating histogram If you convert to categorical, you can sort the counts by descending order:a = randi(10,10,10);histogram(categorical(a), 'DisplayOrder', 'descend'); MATLAB: How to avoid repetition One easy solution based on accumarray:S = size(A);[~,Y,Z] = ndgrid(1:S(1),1:S(2),1:S(3));Y(:) = 1;X = [repmat(B(:),S(3),1),Y(:),Z(:)];C2 = accumarray(X,A(:),[],@mean)And tested:>> isequal(C2,C)ans = 1 Related QuestionHow to count the occurrences of a value for an matrixHow to compute Permutation without repetitionCounting Repeated elements in an array.How i count the values.How to generate two subsets randomly from a matrix without repetitionAn efficient function for k-th combination with no repetition
Best Answer