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 个评论
Azzi Abdelmalek
2013-6-23
If you have
a=[2 3 4]
b=[1 4 0]
What should be the result of comparison?
Lidank Abiel
2013-6-23
Iain
2013-6-24
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
2013-6-24
Iain
2013-6-24
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
2013-6-25
回答(2 个)
Azzi Abdelmalek
2013-6-23
编辑:Azzi Abdelmalek
2013-6-23
a=[2 3 4]
b=[1 4 0]
comp=a<b
12 个评论
Lidank Abiel
2013-6-23
Azzi Abdelmalek
2013-6-23
Ok, but what should be the result in this case?
Lidank Abiel
2013-6-23
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
2013-6-23
Azzi Abdelmalek
2013-6-23
编辑:Azzi Abdelmalek
2013-6-23
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
2013-6-23
编辑:Lidank Abiel
2013-6-23
Azzi Abdelmalek
2013-6-23
I've asked a simple question: what should be the result for the short example you gave.
Lidank Abiel
2013-6-23
Jan
2013-6-23
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
2013-6-24
Jan
2013-6-24
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.
Thorsten
2013-6-24
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]))
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!