<p>Here is my approach to assign a set of parameters to a macroeconcomic model:</p>
<pre><code>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
</code></pre>
<p>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.</p>
<p>For instance, the example from the post can be assigned by</p>
<pre><code>pm=assign_parameters(v)
</code></pre>
<p>and if one wants to study a second model like</p>
<pre><code>v2=[2/3 1/100 1/2]
</code></pre>
<p>one should assign this set of parameters to a different structure name like</p>
<pre><code>pm2=assign_parameters(v2)
</code></pre>
<p>Then both sets remain separated and the first parameter set will not be overwritten by the second.</p>

CC BY-SA 4.0
2020-11-24T17:08:18.887Z
2020-11-24T17:14:38.400Z
2020-11-24T17:14:38.400Z
Holger I. Meinhardt
<p>I am trying to assign a vector of values <code>(v= [1/3 0.01 0.5])</code> to a vector of parameters <code>(w = [alpha beta gamma])</code> 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 <code>gamma = 0.5</code> 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.</p>

CC BY-SA 4.0
2020-11-24T11:59:07.030Z
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?
1muflon1
CC BY-SA 4.0
2020-11-24T12:13:22.900Z
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).
Holger I. Meinhardt
CC BY-SA 4.0
2020-11-24T16:01:01.640Z
@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.
Hokkaido21
CC BY-SA 4.0
2020-11-24T16:01:34.533Z
@HolgerI.Meinhardt thanks a lot. That solves my problem!
Hokkaido21
CC BY-SA 4.0
2020-11-24T16:07:57.143Z
@HolgerI.Meinhardt consider posting it as an answer
1muflon1
CC BY-SA 4.0
2020-11-25T16:48:59.020Z
@Hokkaido21 you mentioned that this answer solved your issue - consider accepting it then (by ticking the check mark under votes)
1muflon1
<macroeconomics><matlab>
How to assign a set of parameters to a macroeconomic model in Matlab?
Hokkaido21
# How to assign a set of parameters to a macroeconomic model in Matlab?

(Asked by: username_0 on 2020-11-24)

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.

**Tags:** macroeconomics, matlab

> **Comments:**
> **username_1**: 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?  
> **username_2**: 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).  
> **username_0**: @username_1 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.  
> **username_0**: @username_2 thanks a lot. That solves my problem!  
> **username_1**: @username_2 consider posting it as an answer  
> **username_1**: @username_0 you mentioned that this answer solved your issue - consider accepting it then (by ticking the check mark under votes)  

---

## 1 answers

### Answer by username_2 on 2020-11-24. Score: 3 | Accepted answer

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.


---

