How to identify duplicate values in an n dimensional array , then club the linked values related to it in another array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 17 Okt. 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?
Antworten (1)
Jan
am 17 Okt. 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
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!