compare value between different arrays

Hi all. I have 2 array that have value. I want to compare each value of each array, but i dont know how to do that. Can somebody help me ? Thanks in advance.

6 commentaires

If you have
a=[2 3 4]
b=[1 4 0]
What should be the result of comparison?
a=[39.4029 46.6748 45.3174 26.4645 21.6932];
b=[36.8585 47.6897 46.7784 26.9878 22.2181];
i want to compare each value of array b to array a, that the result of b approach to a. Value of array a is used here as reference.
By "compare", what do you mean? Do you mean:
1. Check that each element of b is greater than, or equal to, or less than the corresponding element of a?
2. Check that each element of b is greater than, or equal to, or less than ANY element of a?
3. Check that each element of b is within a small error (which you haven't defined) of a (corresponding, or an element)
4. Check that "b" is becoming more like "a"
5. Somethign else?
Lidank Abiel
Lidank Abiel le 24 Juin 2013
option 1 sir
result = b > a; %(b greater than a)
result = b >= a; %(b greater or equal to a)
result = b == a; %(b equal to a)
result = b <= a; %(b less than or equal to a)
result = b < a; %(b less than a)
result is the same length as b, and is 1 (true) when b is that comparison to a, and 0 (false) everywhere else.
all(result) will be 1 (true) if all the elements of b are "that comparison"
any(result) will be 1 (true) if any of the elements of b are "that comparison"
result = b > (5*a); %(b greater than five times a)
Lidank Abiel
Lidank Abiel le 25 Juin 2013
yes, check each element of b less than or equal to a. ( I mean, check b[1] to a[1], b[2] to a[2], etc. If the result are as expected, it will be 1 (true).

Connectez-vous pour commenter.

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 23 Juin 2013
Modifié(e) : Azzi Abdelmalek le 23 Juin 2013
a=[2 3 4]
b=[1 4 0]
comp=a<b

12 commentaires

a=[39.4029 46.6748 45.3174 26.4645 21.6932];
b=[36.8585 47.6897 46.7784 26.9878 22.2181];
i want to compare each value of array b to array a, that the result of b approach to a. Value of array a is used here as reference.
Azzi Abdelmalek
Azzi Abdelmalek le 23 Juin 2013
Ok, but what should be the result in this case?
Lidank Abiel
Lidank Abiel le 23 Juin 2013
I had the training data, which is a. later, I enter test data, namely b. The b value would I compare it with a. if the value of b close to the value of a, then the data is valid. that's what I want to do. is there a way to make it?
Tom
Tom le 23 Juin 2013
Modifié(e) : Tom le 23 Juin 2013
How do you define close?
a=[39.4029 46.6748 45.3174 26.4645 21.6932];
b=[36.8585 47.6897 46.7784 26.9878 22.2181];
tol = 1;
%check that the elements of a and b are within a given tolerance
abs(a-b) <= tol
Lidank Abiel
Lidank Abiel le 23 Juin 2013
ya, like that, but each value from an array sir, not overall ( i mean not (a-b), but maybe like (a1-b1). is it possible ?.
Azzi Abdelmalek
Azzi Abdelmalek le 23 Juin 2013
Modifié(e) : Azzi Abdelmalek le 23 Juin 2013
Do you want to compare the first value of a with the first of b, and so on? To be more clear, please post what should be the result for your example!
Lidank Abiel
Lidank Abiel le 23 Juin 2013
Modifié(e) : Lidank Abiel le 23 Juin 2013
function deteksi_Callback(hObject, eventdata, handles)
% hObject handle to deteksi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global capture
cla(handles.axes3);
cla(handles.axes7);
set(handles.status, 'String', '------');
set(handles.nominal, 'String', '------');
set(handles.euc_uji, 'String', '------');
set(handles.euc_sampel, 'String', '------');
toleran=0;
if(isempty(get(handles.toleransi,'String')))
toleran=93;
else
toleran=eval(get(handles.toleransi,'String'));
end
load dataeuc;
[x y]=size(nilaieuc);
jum=0;
citragray=rgb2gray(capture);
citrafilter=medfilt2(citragray,[3 3]);
citraedge=edge(citrafilter,'canny',[0.01 0.11]);
jlh=20;
citraedgethin=bwmorph(citraedge,'thin',jlh);
citraakhir=imcomplement(citraedgethin);
[ximg2 yimg2]=size(citraakhir);
jum=0;
for i=1:ximg2
for j=1:yimg2
if(citraakhir(i,j)==0)
jum=jum+1;
pos(jum,1)=i;
pos(jum,2)=j;
end
end
end
[ximg3 yimg3]=size(pos);
euclid1=0;
for i=1:ximg3-1
euc(i)= sqrt(((pos(i,1)-pos(i+1,1))^2)+((pos(i,2)-pos(i+1,2))^2));
euclid1=euclid1+euc(i);
end
axes(handles.axes3);
imshow(citraakhir);
euclid1
set(handles.euc_uji,'String',euclid1); %set nilai euclidean gambar di static text
bandingkan=0;
for counti=2:x
counti
euclid2=nilaieuc(counti)
besar=0;
kecil=0;
temp_bandingkan=0;
if(euclid1>=euclid2)
besar=euclid1;
kecil=euclid2;
else
besar=euclid2;
kecil=euclid1;
end
temp_bandingkan=(kecil/besar)*100
if(temp_bandingkan>toleran)
%set(handles.euc_uji,'String',toleran);
if(temp_bandingkan>bandingkan)
bandingkan=temp_bandingkan;
posisikoin=counti;
end
end
end
This is it sir. I want to make like this.
Azzi Abdelmalek
Azzi Abdelmalek le 23 Juin 2013
I've asked a simple question: what should be the result for the short example you gave.
Lidank Abiel
Lidank Abiel le 23 Juin 2013
to save the largest value and it is used as a reference in the percentage of proximity or similarity.
the 'toleran = 93' seems like minimal percentage tolerance. and the 'temp_bandingkan=(kecil/besar)*100' is to know the percentage.
The code does not really answer the question, so I ask again: What is the desired result for the values:
a = [39.4029 46.6748 45.3174 26.4645 21.6932];
b = [36.8585 47.6897 46.7784 26.9878 22.2181];
Lidank Abiel
Lidank Abiel le 24 Juin 2013
I want that values used to percentage of proximity.
My plan, i set value for tolerance, example, tolerance = 93. Then, i process image to get the euclidean value. The result above, is value from 2 image. and then, i want to calculate 2 value above ( maybe divided ) if the result approach to value tolerance, so, the image have percentage minimal similarity 90%.
I'm sorry make all of you confused. I'm new in programming. So, I explained it according to my knowledge.
Thanks in advance.
Thanks for the explanantions. Unfortuantely I do not understand this:
i want to calculate 2 value above ( maybe divided ) if the result approach to value tolerance, so, the image have percentage minimal similarity 90%.
I still do not know hwta kind of result you expect for the above mentioned input data. Are you able to calculate it manually or give a definition of the calculations? In the comments to the question you wrote "i want to compare each value of array b to array a". As soon as it is explained, what "campare" means explicitly, I assume the problem can be solved in seconds. So please try to explain this clearly.

Connectez-vous pour commenter.

Thorsten
Thorsten le 24 Juin 2013
You can compute two fractions a/b and b/a, and then take the minimum to ensure that the value is not above 100%. Then take the minimum of these values to get "percentage minimal similarity"
min_similarity = min(min([a./b; b./a]))

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by