Take a look at this article. Multidimensional arrays can only be dynamic on the first dimension, while the others must be static.
I'm not quite used to them, but I believe you can use matrices pretty much as how you would use 2-dimension arrays:
#property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { matrix mat; mat.Reshape(3,3); mat[0][0] = 123; double val = mat[0][0]; Print("Value = ", val); } //+------------------------------------------------------------------+
- www.mql5.com
Take a look at this article. Multidimensional arrays can only be dynamic on the first dimension, while the others must be static.
I'm not quite used to them, but I believe you can use matrices pretty much as how you would use 2-dimension arrays:
It's just not only about the first dimension, in order to declare from the second dimension onward, only constant values ( numbers ) are allowed, I tried to use variables to declare a second and a third dimension and it still didn't let me.
For the matrices I tried to used them, even though my logic checks out, for my specific use case I was not able to use them as general input into an ai model. In my case I had an input shape { 101, 200, 2 }, I complement this with an array of matrixf with 200 rows and 2 columns, I do believe that when setting the input shape for the model, despite having all the necessary data, when doing the check on the size of what the model is expecting and the new structure of matrix, the dimension do not checks out.
In the end I was able to solve my problem by refactoring my model by using constant values for the dimension of a multi-dimensional arrays used as input structure ( Ugly af ).
Is there a better way to make complex structures of dimensions not known at runtime ?It's just not only about the first dimension, in order to declare from the second dimension onward, only constant values ( numbers ) are allowed, I tried to use variables to declare a second and a third dimension and it still didn't let me.
For the matrices I tried to used them, even though my logic checks out, for my specific use case I was not able to use them as general input into an ai model. In my case I had an input shape { 101, 200, 2 }, I complement this with an array of matrixf with 200 rows and 2 columns, I do believe that when setting the input shape for the model, despite having all the necessary data, when doing the check on the size of what the model is expecting and the new structure of matrix, the dimension do not checks out.
In the end I was able to solve my problem by refactoring my model by using constant values for the dimension of a multi-dimensional arrays used as input structure ( Ugly af ).
Is there a better way to make complex structures of dimensions not known at runtime ?- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
As the title said, I'm getting this annoying error for something that should be trivial, why can't I use variables to declare the dimensions of an array ?
Practically I do not know the values for the dimensions as mat would be declared with random values that range between at least 50 and 200.
Can someone enlighten me on how can I achieve the same result in mql5 ?