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)
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
sakshi chopra
sakshi chopra am 17 Okt. 2021
I want B to look like as
if A=[1 8 ;
3 4;
10 9;
8 5;
9 6]
B=[ 1 8 5
3 4 0
10 9 6]
Jan
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
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
  1 Kommentar
sakshi chopra
sakshi chopra am 17 Okt. 2021
Thanks for the help , but this doesn't solve my problem. If possible please suggest some another solution, i have tried to clarify my problem again.

Melden Sie sich an, um zu kommentieren.

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!

Translated by