Dear all:
I parse a structure into a function, which build the system matrix for a model. The code looks something like this:
function [m] = test(param)%%SETUP GLOBAL PARAMETERS
F = fieldnames(param);for i = 1:length(F) field = F{i}; assignin('caller', field, param.(field));end%%SET UP MATRICES FOR SOLVING THE MODEL
m = [kappa, alpha];end
The structure param looks like the following:
param.kappa = 0.8;param.alpha = 1;
but when I run the function test, matlab returns the following complain:
??? Undefined function or variable 'kappa'.
I would imagine 'assignin' assigns the value into the kappa, so kappa should be automatically defined, but this is not the case. If I take away kappa and just leave alpha in the matrix, matlab complains about alpha is not defined. Any ideas why this happens?
PS: The reason I do this is not obvious in this simplified function. My model is very complex and involves changing parameters in simulations, so I want to remain the variable name as their name rather than some vector/matrix index to minimise errors.
Thanks alot in advance!
Cheers Ben
Best Answer