Syntax
[C,ia,ic,h]=uniquehist(A,[])
Input Parameter
Output Parameter
C : | | unique arrary, may be sorted |
ia : | | index vector ia |
ic : | | index vector ib |
h : | | number of entities of C in A |
Examples
L=1+floor(rand(10,1)*10)
L=1+floor(rand(100,2)*10)
[a,~,~,h]=uniquehist(rounddiv(ELunsort(L),2),'rows'),[a h]
uniquehist(rounddiv(ELunsort(L),20))
uniquehist(rounddiv(ELunsort(L),20),'rows')
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, uniquehist
, is an extension of the MATLAB unique
function. It identifies unique elements in an array and calculates the frequency of each unique element.
Input Parameters
- A: The input array from which unique elements are to be identified.
- varargin: Additional optional parameters, such as 'rows', which specifies if the operation should consider rows as unique entities.
Output Results
- C: An array of unique elements from A, potentially sorted.
- ia: An index vector indicating the first occurrence of each unique element in A.
- ic: An index vector such that C(ic) = A.
- h: A histogram count of the number of occurrences of each unique element in A.
Algorithm Steps
- Call the
unique
function with input array A and any additional parameters to get unique elements C, and index vectors ia and ic.
- Check if the 'rows' option is specified in
varargin
. If so, set rows
to true.
- Initialize a zero vector
h
with the same number of rows as C to store histogram counts.
- Iterate over each unique element in C:
- If
rows
is true, use ismember
to count occurrences of each unique row in A.
- If
rows
is false, compare each element in A to the current unique element and sum the occurrences.
- If no output arguments are specified, plot the results using a custom plotting function.
Algorithm explaination created using ChatGPT on 2025-08-19 01:37. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21