elementCount
Count elements in a vector.
Contents
Syntax
- [sortedElement, count] = elementCount(in, orderBy)
Description
sortedElement = elementCount(in) returns the sorted elements.
[sortedElement, count] = elementCount(in) also returns the element count for each sorted element.
[uniqElement, sortedCount]=elementCount(in, 'count') returns the element counts in decreasing order.
Example
in = [5 1 5 5 7 9 9]; fprintf('in = %s\n', mat2str(in)); fprintf('"[sortedElement, count] = elementCount(in)" produces the following output:\n'); [sortedElement, count] = elementCount(in); fprintf('sortedElement = %s\n', mat2str(sortedElement)); fprintf('count = %s\n\n', mat2str(count)); in = {'xy', 'cd', 'ef', 'xy', 'cd', 'xy'}; fprintf('in = %s\n', cell2str(in)); fprintf('"[sortedElement, count] = elementCount(in)" produces the following output:\n'); [sortedElement, count] = elementCount(in); fprintf('sortedElement = %s\n', cell2str(sortedElement)); fprintf('count = %s\n\n', mat2str(count)); in = {'xy', 'cd', 'ef', 'xy', 'cd', 'xy'}; fprintf('in = %s\n', cell2str(in)); fprintf('"[element, sortedCount] = elementCount(in, ''count'')" produces the following output:\n'); [element, sortedCount] = elementCount(in, 'count'); fprintf('element = %s\n', cell2str(element)); fprintf('sortedCount = %s\n\n', mat2str(sortedCount));
in = [5 1 5 5 7 9 9]
"[sortedElement, count] = elementCount(in)" produces the following output:
sortedElement = [1 5 7 9]
count = [1 3 1 2]
in = {'xy', 'cd', 'ef', 'xy', 'cd', 'xy'}
"[sortedElement, count] = elementCount(in)" produces the following output:
sortedElement = {'cd', 'ef', 'xy'}
count = [2 1 3]
in = {'xy', 'cd', 'ef', 'xy', 'cd', 'xy'}
"[element, sortedCount] = elementCount(in, 'count')" produces the following output:
element = {'xy', 'cd', 'ef'}
sortedCount = [3 2 1]