# Questions about Macro Language Related to Vectors

**URL:** <https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343>\
**Category:** Macro-language\
**Created:** [22 March 2025 12:02 UTC](https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343 "2025-03-22T12:02:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KASD](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@KASD](https://forum.dynare.org/u/KASD)\
**Post date:** [22 March 2025 12:02 UTC](https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343/1 "2025-03-22T12:02:48Z")

</div>

Hello everyone,

I’m currently facing a few issues when using macro-language in Dynare. I would appreciate any help or insights!

### 1. How to Access Elements in a MATLAB Vector Using Macro Language?

I tried to extract an element from a MATLAB vector using macro-language, but it resulted in an error. Here’s what I attempted:

```auto
xx = [1; 2; 3];
@define x1 = xx(1)

```

This approach did not work as expected. How can I correctly access the first element of the `xx` vector within a macro definition?

### 2. Accessing Elements from a Macro-Defined Vector

In another case, I defined a vector directly in the macro language and wanted to retrieve its first element. The following code also produced an error:

```auto
@define xx = [1, 2, 3]
@define x1 = @{xx(1)}

```

### 3. Error When Using Macro-Defined Vectors in the `shocks` Block

I’m encountering a syntax error when trying to define a `shocks` block using macro-defined vectors. Here’s the code I wrote:

```auto
@#define xx = [3.1, 3.5]
@#define leg = length(xx)

shocks;
var x;
periods 1:@{leg};
values @{xx};
end;

```

However, this results in the following error:

```auto
syntax error, unexpected '['

```

Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [23 March 2025 10:13 UTC](https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343/2 "2025-03-23T10:13:31Z")

</div>

What is the ultimate goal you are trying to achieve?

1. The is not a use-case that is supported. At runtime of the macroprocessor, the content of the Matlab variable is not yet known. Depending on what you are trying to do, there may be other ways to implement it.
2. A correct code would be

```auto
@#define xx = [1, 2, 3]
@#define x1 = (real)xx[1]
@{x1}

```

1. That is also not easily feasible, but there is a straigthforward workaround by calling the mod-file with a Matlab script.

---

<div class="post-metadata">

**Author:** ![KASD](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@KASD](https://forum.dynare.org/u/KASD)\
**Post date:** [23 March 2025 10:33 UTC](https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343/3 "2025-03-23T10:33:39Z")

</div>

Dear Professor,

Thank you once again for your help.

In fact, I am currently trying to perform a perfect foresight simulation of an RBC model using an exogenous TFP sequence, possibly with a trend.

I would like to set the steady state in initval to correspond to the initial value of the TFP sequence, use the middle part of the sequence in shocks, and set the steady state in endval to the final value of the TFP sequence.

I’ve managed to run the simulation by setting everything manually, but I’m hoping to write the code more elegantly using the macro language.

Now I understand this is much complicated than I think. But still, I appreciate your kindly help!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [30 March 2025 14:19 UTC](https://forum.dynare.org/t/questions-about-macro-language-related-to-vectors/27343/4 "2025-03-30T14:19:56Z")

</div>

That very much sounds like a case where you should directly manipulate `oo_.endo_simul` and `oo_.exo_simul` before calling `perfect_foresight_solver`.
