RESETREPLICATES
RESETREPLICATES - change the value of replicated elements in a matrix
For vectors, R = RESETREPLICATES(X) returns a vector R in which the re-ocurrences (replicates) of the values in X are set to NaN, except for their first occurrence. For 2-D matrices, RESETREPLICATES(X) looks for replicates in each column of X separately. For N-D arrays the function operates along the first non-singleton dimension of X.
RESETREPLICATES(X,DIM) operates along the dimension DIM. When DIM is empty, the function operates along the first non-singleton dimension.
RESETREPLICATES(X,[],V) sets all replicates to the value V instead of NaN. V must be a scalar. NaNs in X are ignored.
Examples:
resetreplicates([1 2 2 1 0 3 4 5 3 2])
% -> [1 2 NaN NaN 0 3 4 5 NaN NaN]
A = [1 0 0 1 ; 1 2 3 4 ; 2 2 5 1 ; 3 0 0 3]
resetreplicates(A) % = resetreplicates(A,1)
% 1 0 0 1
% NaN 2 3 4
% 2 NaN 5 NaN
% 3 NaN NaN 3
resetreplicates(A,2)
% 1 0 NaN NaN
% 1 2 3 4
% 2 NaN 5 1
% 3 0 NaN NaN
resetreplicates(A,1,0) % = resetreplicates(A,[],0)
% 1 0 0 1
% 0 2 3 4
% 2 0 5 0
% 3 0 0 3
See also unique, ismember
fillzero, replace (on the File Exchange)
Version 1.1 (oct 2008)
Cite As
Jos (10584) (2026). RESETREPLICATES (https://se.mathworks.com/matlabcentral/fileexchange/21691-resetreplicates), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | consistent naming into RESETREPLICATES |
