0
$\begingroup$

I am trying to assign a vector of values (v= [1/3 0.01 0.5]) to a vector of parameters (w = [alpha beta gamma]) in order to make Matlab save the entries of the value vector as the parameter values. So for instance the third entry of v should be assigned to the third value in w. Matlab should then save gamma = 0.5 in the workspace. I was not able to figure out how to do it. My solution always just overwrites the other vector but does not save the entries in the workspace. I hope, someone can help me out.

$\endgroup$
6
  • $\begingroup$ I dont get why you just dont define alpha = 1/3 beta=0.01 gamma= 0.5 separately and then if you need it in a vector form just do that with w = [alpha beta gamma]. Wouldnt this do what you want? $\endgroup$
    – 1muflon1
    Commented Nov 24, 2020 at 11:59
  • 2
    $\begingroup$ The simplest approach would be to write a function that assigns the parameter set to the structures variables. Hence, para.alpha=v(1);para.beta=v(2), and para.gamma=v(3). $\endgroup$ Commented Nov 24, 2020 at 12:13
  • $\begingroup$ @1muflon1 I am writing a function which uses the vector as input. In order to vary the entries, I was trying to create something like this. $\endgroup$
    – Hokkaido21
    Commented Nov 24, 2020 at 16:01
  • $\begingroup$ @HolgerI.Meinhardt thanks a lot. That solves my problem! $\endgroup$
    – Hokkaido21
    Commented Nov 24, 2020 at 16:01
  • $\begingroup$ @HolgerI.Meinhardt consider posting it as an answer $\endgroup$
    – 1muflon1
    Commented Nov 24, 2020 at 16:07

1 Answer 1

3
$\begingroup$

Here is my approach to assign a set of parameters to a macroeconcomic model:

function para=assign_parameters(v)

if length(v)==3
   para.alpha=v(1);
   para.beta=v(2);
   para.gamma=v(3);
else
   error('parameter input has not correct format of length 3!');
end

The advantage is that the parameter set can be changed on the fly. That is, one can assign to the same underlying macroeconomic model a different set of numerical parameters without observing any conflict among the analyzed models. This would allow a quick comparison of model outcomes and ensure a clear as well as consistent model environment.

For instance, the example from the post can be assigned by

pm=assign_parameters(v)

and if one wants to study a second model like

v2=[2/3 1/100 1/2]

one should assign this set of parameters to a different structure name like

pm2=assign_parameters(v2)

Then both sets remain separated and the first parameter set will not be overwritten by the second.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.