Write custom function for bsxfun

1 visualización (últimos 30 días)
Harold
Harold el 7 de Mayo de 2013
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.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by