MATLAB: How to change anonymous function to take array parameter and subject to ranges

anonymous function

Hi, I have a working anonymous function that takes a vector of size 1×3 and I want to expand this to 3×3. The function is named mu_x and looks like this
mu_x=@(t) f_lx(t,param);
function res=f_lx(x,param)
a=param(1);
b=param(2);
c=param(3);
res = zeros(size(x));
ind = x>100;
res(ind) = a+b*exp(c*100)+(x(ind)-100)*0.001;
res(~ind) =a+b*exp(c*x(~ind));
end
The 1×3 param is now [a b c] and the 3×3 parameter I want to use is subject to x such as:
x=65-59 param(:,1)
x=70-76 param(:,2)
x=77-106 param(:,3)
just to clarify the new param looks something like this
a1 b1 c1
a2 b2 c2
a3 b3 c3
How can the anonymous function be changed to consider the ranges of x and new format of param?

Best Answer

You need to be careful with how you build your anonymous function:
mu_x = @(t) f_lx(t,param);
In the above line, t is an argument that can change with every call, but param is a fixed snapshot of whatever it happens to be at the time you create mu_x. Changing param downstream in your code will have no effect on mu_x. The param in mu_x will still be that fixed snapshot of the param that existed at the time mu_x was created. If you want to use a new param with mu_x, you will need to recreate mu_x from scratch (i.e., execute the above line again).
Bottom line: If you originally created mu_x with a 1x3 param, and then downstream in your code change param in any way (to a new 1x3 or to a 3x3 etc), then you will have to recreate mu_x from scratch in order for it to use that new param.
Simpler: Just call f_lx directly ... what do you need that mu_x for?