From: Daniel Nwosu on
I have a bunch of functions that give results based on specific parameters. For example, say I have a function A= multiplier_m (y, z) and y=x^2 there's another function F=divider_d (b, c) and c=t+1 or something. A script file runs the difference between both functions: final_answer = multiplier_m (y, z) - divider_d (b, c). Assuming all variables/parameters (x, z, b and t) have already been assigned specific values, I want to be able to vary the value of x alone while also using same old assigned values for the other variables i.e. only x is changing. I also want to be able to vary the value of say c, while also using the same old assigned values for the other variables. Is there a way I can write all the variables in a different script file and just vary whichever one I want while it uses the new varied value and the other same ones to give me a result for final_answer (like I don't want
to have to open ALL my functions and change them specifically from there each time I want to vary any of the parameters) ? I don't mind explaining this question further if it seems to make no sense.
From: nanren888 on
"Daniel Nwosu" <chimez4(a)hotmail.com> wrote in message <hp2tqv$66k$1(a)fred.mathworks.com>...
> I have a bunch of functions that give results based on specific parameters. For example, say I have a function A= multiplier_m (y, z) and y=x^2 there's another function F=divider_d (b, c) and c=t+1 or something. A script file runs the difference between both functions: final_answer = multiplier_m (y, z) - divider_d (b, c). Assuming all variables/parameters (x, z, b and t) have already been assigned specific values, I want to be able to vary the value of x alone while also using same old assigned values for the other variables i.e. only x is changing. I also want to be able to vary the value of say c, while also using the same old assigned values for the other variables. Is there a way I can write all the variables in a different script file and just vary whichever one I want while it uses the new varied value and the other same ones to give me a result for final_answer (like I don't
want
> to have to open ALL my functions and change them specifically from there each time I want to vary any of the parameters) ? I don't mind explaining this question further if it seems to make no sense.

Daniel,
I do not follow the function explanations, nor your requirement.
Regardless, I have some comments that maybe could help. If I am explaining the obvious, then sorry. Wait for a better answer?
---------- { Guess 1 ) ---------------
x = <value>;
z = <value>;
b = <value>;
t = <value>;
weirdFunc(z,x,b,t);
weirdFunc(z,7,b,t); % Substitute value for x
weirdFunc(z,3,b,t); % Substitute value for x
weirdFunc(z,x,4,t); % Substitute value for b
....
---------- { Guess 2 ) ---------------
zPosn = 1;
xPosn = 2;
bPosn = 3;
tPosn = 4;

defaultParamC = {z,x,b,t};
thisParamC = defaultParamC;
thisParamC{bPosn} = newBvalue;
weirdFunc(thisParamC{:});

thisParamC = defaultParamC;
thisParamC{xPosn} = newXvalue;
weirdFunc(thisParamC{:});


thisParamC = defaultParamC;
thisParamC{xPosn} = newXvalue;
weirdFunc(thisParamC{:});
....

---------- { Guess 3 ) ---------------

weirdFunc(z,x,b,t);
weirdFunc([],[],5,[]); % function remembers previous values?
weirdFunc([],[],7,[]); % function remembers previous values?
weirdFunc([],4,[],[]); % function remembers previous values?

-----------------------
But:
Essence: consider [] & if necessary "persistent".
I guess, the traditional way in Matlab for parameters that are not always there is to use something like;
func(p1,p2);
& call with func([],p2)
isempty(p1) inside the function allows you to check & see if you have an actual parameters.
In your case, it seems that you want default values, or perhaps persistent ones.
your could have a local default, or persistent value that gets used if none is provided. With this comes the headache of having to be really careful about what value is being used.

In a rather different situation I sometimes have many parameters so I have come to use structs for parameters.
func(paramS)
if the paramS is struct('p1',3,'p2',5) then both are used.
Perhaps with more meaningful names in my case.
if I call it with paramS = struct('p2',35), then the absence of the p1 field means it uses a default values. This is basically the same as the [] construction above, I just don't need to bother about parameter order, at the expense of having a few convenient utilities to combine structures.

Any help?