How to identify duplicate values in an n dimensional array , then club the linked values related to it in another array
1 view (last 30 days)
Show older comments
How to identify duplicate values in an n dimensional array , then club the linked values related to it in another array
for example
A= [ 1 8 10 4
1 8 4 0]
how to identify the repeated value and then club the value in another matrix B and set repeated values to null
3 Comments
Jan
on 17 Oct 2021
I have no idea, how B can be constructed based on A. You asked for duplicate elements in A. Now there is one 5 only in A, so why does 5 occur in B?Why is B 3x3 and not 9x1?
Answers (1)
Jan
on 17 Oct 2021
A = [ 1 8 10 4; ...
1 8 4 0];
T = isMultiple(A);
B = A(T) % ? or what do you want?
A(T) = 0;
function T = isMultiple(A)
[S, idx] = sort(A(:).');
m = [false, diff(S) == 0];
ini = strfind(m, [false, true]);
m(ini) = true; % Mark 1st occurence in addition
T(idx) = m;
end
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!