Write custom function for bsxfun
1 view (last 30 days)
Show older comments
I'm needing to compare to matrices together. The catch here is that I don't want to return "true" if there is a match between A and B where both elements are zero. For example:
A = [0 0 0 0 0 0;...
0 1 0 0 0 0;...
0 0 0 0 4 0;...
0 0 0 0 0 0];
B = [0 0 0 0 0 0;...
0 1 0 0 0 0;...
0 0 0 0 4 0;...
0 0 0 0 0 0];
I want bsxfun to return
[0 0 0 0 0 0;...
0 1 0 0 0 0;...
0 0 0 0 1 0;...
0 0 0 0 0 0];
However, this may get a little more tricky. A and B matrices will not necessarily always be of equal size. For example A may be
A = [0 0 0 0 0 0 0;...
0 1 0 0 0 4 0;...
0 0 0 0 0 0 0;...
0 0 0 0 0 0 0;...
0 0 0 0 0 0 0];
What I am aiming to do is as follows:
Take every value in A and compare it with every value in B. If there is a match and the both values are not equal to 0, calculate the distance between these values (using pythagorean theorem; use row and column indices of A and B to calculate the distance).
I would like to come up with some sort of cost function. The cost function basically is a value of how close the input matrix A is to a matrix B in a database. For instance, both A and B have two values that are the same. The values in A are located one row down and one column over than the values in B. Now if I compare A against another matrix C where the values are now 3 rows down and 1 column over, my cost function would find the matrix that returns the minimum error between the compared matrices; in this case it would return B as the matching matrix. I would of course incorporate a threshold value for the error so that matches that are not supposed to be matches are avoided.
0 Comments
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!