How to identify duplicate values in an n dimensional array , then club the linked values related to it in another array

조회 수: 1 (최근 30일)
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
sakshi chopra
sakshi chopra 2021년 10월 17일
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 2021년 10월 17일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 10월 17일
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
sakshi chopra
sakshi chopra 2021년 10월 17일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by