I have a situation where the same multi-variable argument is used in several different functions defined with function handles. I would like to define the arguments as an array so that I don't have to keep copying the specific list of values in every instance. It would be much easier to double-check my code that way and it would be more flexible.
Here's a toy example:
Suppose I have a function simulates data that lies approximately on a parabolic curve. I would like to calculate datasets for three combinations of polynomial coefficients as well as the difference in the y-values for the arrays from a reference array.
x= @(NN) -NN:NN;
y = @(y0,a,b,NN) y0 + a*x(NN) + b*x(NN).^2
yREF = y(1,2,3,10);
yDIFF = @(y0,a,b,NN) yREF - y(y0,a,b,NN)
xDATA = x(10);
yDATA1 = y(0.85,2.1,3.2,10);
yDATA2 = y(1.1,1.9,3.5,10);
yDATA3 = y(1.02,1.98,2.9,10);
To generate the differences I have to manually copy the parameter values which is annoying:
yDIFF1 = yDIFF(0.85,2.1,3.2,10);
yDIFF2 = yDIFF(1.1,1.9,3.5,10);
yDIFF3 = yDIFF(1.02,1.98,2.9,10);
Is there a way where I can define the arguments just once and use them later? I'm imagining something like the following
coefs1 = [0.85 2.1 3.2 10]
coefs2 = [1.1 1.9 3.5 10]
yDATA1 = y(coefs1)
yDIFF1 = y(coefs1)
I'm sure this is trivial but I can't figure out how to do it. Thanks!!