Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to release indexes in an array

조회 수: 1 (최근 30일)
aya qassim
aya qassim 2019년 1월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
I have the array
arr=[-9,6,-2,0,4,98,2,-5,0,-9,4,3,1,1,-5]
I have wrote this code and found out how many time each element is in the array and the places of the numbers.
how can I make the numbers that appear more than once un the array appear just one time
A=arr;
t=length(A);
A1=repmat(A,t,1);
A2=A';
c=(A1==A2);
r=sum(c);
e=find(r~=1);
disp(e)

답변 (2개)

madhan ravi
madhan ravi 2019년 1월 16일
  댓글 수: 1
aya qassim
aya qassim 2019년 1월 16일
thank you,
but If I want to continue my code, do you know how can I can do it?

Guillaume
Guillaume 2019년 1월 16일
A much simpler way to obtain your r (and e):
[uvals, ~, id] = unique(arr);
r = accumarray(id, 1);
e = find(r > 1);
which also gives you the unique values and answers your how can I make the numbers that appear more than once un the array appear just one time

태그

Community Treasure Hunt

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

Start Hunting!

Translated by