Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Dr. Hareesha N G
Dr. Hareesha N G le 4 Jan 2018
Commenté : Image Analyst le 26 Jan 2018
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 commentaires
Birdman
Birdman le 4 Jan 2018
Modifié(e) : Birdman le 4 Jan 2018
Have you tried my edited answer?
Dr. Hareesha N G
Dr. Hareesha N G le 4 Jan 2018
Yes sir. It works with data I had given before. But not for the data generated from the codes attached with the previous comment.

Connectez-vous pour commenter.

Réponse acceptée

Birdman
Birdman le 4 Jan 2018
Modifié(e) : Birdman le 4 Jan 2018
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 commentaires
Dr. Hareesha N G
Dr. Hareesha N G le 4 Jan 2018
Modifié(e) : Dr. Hareesha N G le 4 Jan 2018
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 le 4 Jan 2018
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

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 4 Jan 2018
Modifié(e) : Image Analyst le 4 Jan 2018
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 commentaire
Dr. Hareesha N G
Dr. Hareesha N G le 4 Jan 2018
Sir, This code didnt work, as i dont have statistics toolbox. Thanks for your time!!

Connectez-vous pour commenter.


Poornimadevi P
Poornimadevi P le 26 Jan 2018
hi, please help me to find duplication in sequence of image and send me a code .

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by