Minimizing with fminbnd - how to use it for a matrix?

2 views (last 30 days)
Hello,
I want to minimize the difference between theory value and measured value to calculate the parameter x.
Here's my function to minimize:
function difference = FUN_NAME(x,MEASURE,Qs,Qe,g)
omega = Qs/Qe-eps;
Rinf = (((sqrt(1-omega*g))-(sqrt(1-omega))))/(((sqrt(1-omega*g))+(sqrt(1-omega))));
gamma = 2*(sqrt(1-omega))*(sqrt(1-omega*g));
THEORY = (Rinf*(exp(gamma*x)-exp(-gamma*x)))/(exp(gamma*x)-Rinf^2*exp(-gamma*x));
difference = (THEORY-MEASURE)^2;
And everything works fine if I use fminbnd for any specific pixel of my MEASURE matrix (201x451), for example:
x=fminbnd('FUN_NAME',0,100,[],0.5189,2.1669,2.1669,0.83)
it gives me proper value of x. But I want to use it for my whole matrix and here's the problem. I'm trying to do it in this way:
for i=201
for j=451
x(i,j)=fminbnd('FUN_NAME',0,100,[],MEASURE(i,j),2.1669,2.1669,0.83)
end
end
Unfortunately it gives me something like this:
wrong value 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
....................
0 0 0 0 0 0 wrong value
There's always wrong value of x in the first and in the last pixel, the rest pixels are 0. Is there soemthing worng with this for loop?
Thanks for all the help.

Accepted Answer

Matt J
Matt J on 20 May 2014
Edited: Matt J on 20 May 2014
One problem I see is that your loop range is only the single pair i=201, j=451. Perhaps you really meant
x=nan(201,451);
for i=1:201
for j=1:451
fun=@(z) FUN_NAME(z, MEASURE(i,j),2.1669,2.1669,0.83);
x(i,j)=fminbnd(fun,0,100);
end
end
Note also the more modern way of attaching fixed parameters to functions.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!