필터 지우기
필터 지우기

How to print duplicate (repeated) value from an array?

조회 수: 1 (최근 30일)
Dr. Hareesha N G
Dr. Hareesha N G 2018년 1월 4일
댓글: Image Analyst 2018년 1월 26일
Dear experts,
I have to print the duplicate (repeated) value from the following array. Please help me.
104.96
81.01
-35.21
-150.76
145.22
104.96
20.62
-90.79
  댓글 수: 2
Birdman
Birdman 2018년 1월 4일
편집: Birdman 2018년 1월 4일
Have you tried my edited answer?
Dr. Hareesha N G
Dr. Hareesha N G 2018년 1월 4일
Yes sir. It works with data I had given before. But not for the data generated from the codes attached with the previous comment.

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

채택된 답변

Birdman
Birdman 2018년 1월 4일
편집: Birdman 2018년 1월 4일
More simpler way:
[C,~,~]=unique(v);
val=sum(v)-sum(C)
Edit after Image Analyst's warning:(works for any situation)
[C,~,idx]=unique(v,'stable');
n=accumarray(idx(:),1);
vals=C(find(n~=1))
  댓글 수: 3
Dr. Hareesha N G
Dr. Hareesha N G 2018년 1월 4일
편집: Dr. Hareesha N G 2018년 1월 4일
Dear Image Analyst (Expert), Thanks for the help.
The code given by you works well in separate window. But, not along with code attached with this comment.
This is probably due to approximation in the values.
Will you please help me to resolve this issue?
Thanks in advance.
%%%%%%%%%%%%%%%%Code%%%%%%%%%%%%%%%%%%%% Eq1(x, y) = - (7542936551605719*x^4*y^4)/1125899906842624 + (10696071671072981*x^4*y^2)/1125899906842624 - (2027189923366279*x^4)/1125899906842624 + (344734164264965*x^3*y^3)/17592186044416 + (344734164264965*x^3*y)/17592186044416 + (11483540892015981*x^2*y^4)/562949953421312 + (37717533301837501*x^2*y^2)/562949953421312 + (5967794263776541*x^2)/562949953421312 + (344734164264965*x*y^3)/17592186044416 + (344734164264965*x*y)/17592186044416 - (5518597172048345*y^4)/1125899906842624 - (7318236082770031*y^2)/1125899906842624 - 22065837056766665/1125899906842624; Eq2(x, y) = (7824422850630965*x^4*y^3)/1125899906842624 - (2308676222391525*x^4*y)/1125899906842624 + (10019323566700193*x^3*y^4)/1125899906842624 + (4503576938460753*x^3*y^2)/562949953421312 - (1012169689778687*x^3)/1125899906842624 + (2308676222391525*x^2*y^3)/562949953421312 - (7824422850630965*x^2*y)/562949953421312 - (7994984187142819*x*y^4)/1125899906842624 - (13510730815382259*x*y^2)/562949953421312 - (19026477443621699*x)/1125899906842624 - (3207070405847915*y^3)/1125899906842624 - (13340169478870405*y)/1125899906842624; Eq1(x,y)=simplify((subs(Eq1(x,y),{a1,a2,a3},[1.41421 1.41421 0.8660254]))); Eq2(x,y)=simplify((subs(Eq2(x,y),{a1,a2,a3},[1.41421 1.41421 0.8660254]))); E1=Eq1(x,Y(1,1)); [X1]=double(solve(E1));
E2=Eq2(x,Y(1,1)); [X2]=double(solve(E2)); [X]=[X1;X2]; format bank % bank displays output in its shortest form, like fprintf statement for i = X(:,1); ver_1=double(Eq1(i,Y(1,1))); ver_2=double(Eq2(i,Y(1,1))); [ver] = [ver_1 ver_2]; end for i= X(:,1) [v]=atand(X)*2; end [C,~,idx]=unique(v,'stable'); n=accumarray(idx(:),1); vals=C(find(n~=1))
Image Analyst
Image Analyst 2018년 1월 4일
Hareesha, it looks like you accepted Birdman's answer, and that doesn't require the stats toolbox, so go with that.
Also, you might want to read this link

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

추가 답변 (2개)

Image Analyst
Image Analyst 2018년 1월 4일
편집: Image Analyst 2018년 1월 4일
Here is one way:
v = [...
104.96
81.01
-35.21
-150.76
145.22
104.96
20.62
-90.79]
distances = pdist2(v, v) % In Stats toolbox
% Find where distances = 0
[rows, columns] = find(distances == 0)
for k = 1 : length(rows)
if rows(k) ~= columns(k) % Ignore diagonals
fprintf('Element at row %d (%f) is a repeat.\n', rows(k), v(rows(k)));
end
end
It shows:
Element at row 6 is a repeat.
Element at row 1 is a repeat.
  댓글 수: 1
Dr. Hareesha N G
Dr. Hareesha N G 2018년 1월 4일
Sir, This code didnt work, as i dont have statistics toolbox. Thanks for your time!!

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


Poornimadevi P
Poornimadevi P 2018년 1월 26일
hi, please help me to find duplication in sequence of image and send me a code .

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by