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

4 次查看(过去 30 天)
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 个评论
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.

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 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by