From: Ali on
Hi

i have a function in .m that have 2 matrices as input and compute the value of crossed correlation between both matrices.

i want to optimize this function with fminsearch
i see the help of fminsearch, i apply it but an error i had,
so i need a help about how to use this function.

my function is the following:

function fun=cc_metric(A,B)

A1=A.*A;
A2=sum(sum(A1));

B1=B.*B;
B2=sum(sum(B1));

den=sqrt(A2*B2);

num=sum(sum(A.*B));

fun=-1*(num/den);
From: Matt J on
Ali <za_ali_80(a)hotmail.com> wrote in message <447240783.3382.1277475204773.JavaMail.root(a)gallium.mathforum.org>...
> Hi
>
> i have a function in .m that have 2 matrices as input and compute the value of crossed correlation between both matrices.
>
> i want to optimize this function with fminsearch
> i see the help of fminsearch, i apply it but an error i had,
> so i need a help about how to use this function.

Help like that will be hard to get without displaying your function call and the error messages. I would imagine one problem is that you expressed your optimization variables as a matrix, rather than a vector.

Regardless, you do not need fminsearch to optimize the cross correlation, since the solution is known. The optimum correlation is attained when A=constant*B. That's basic Cauchy-Schwartz.



> A1=A.*A;
> A2=sum(sum(A1));
======

Incidentally, also, you'll get faster and more readable code if you write things like the above as follows

A2=sum(A(:).^2)