No practical experience here, but it looks like you can use the [] operator:
double operator[](const int i) const;
Like so:
CMatrixDouble m(4,4); m[0][0] = 0.5;
No practical experience here, but it looks like you can use the [] operator:
Like so:could get
First of all thanks for your reply, I tried it,
but it throws this:
There are a lot of open questions on my mind, as to how to correctly use operator, there seems to be no documentation on that. Also the documentation on the Standard Library seems pretty scarce. Then I am pretty new to OOP AND OOP in MQL is not the same as in C++, because then it would be easy to get help or informations from the outside or different sources.
Now when playing around with it a little, this was the closest I could get to zero compilation errors:
#include <Math/Alglib/matrix.mqh> int OnInit() { CMatrixDouble doubleMatrix =new *CMatrixDouble(4,4); return(INIT_SUCCEEDED); }
The code above even showed me the correct overload CMatrixDouble(const int n, const int m), so I guess something must have been right. But it also throws this:
The cursor is in front of the asterisk. What identifier does it mean?
So I am not sure how to do this here, the thought behind it is building an array of arrays. I have a suspicion that it doesn't work in MQL but I still have doubts because this would be a very crappy approach to OOP then... If it is really not possible, I might as well build a 2D double matrix on the basis of a single array of n*m fields and provide access through a custom function and put all of it inside an own class...
Another problem might be that I am pretty new to pointers. Although I have made an array of the Type CChartObjectsShapes before, I somehow didn't need Pointers for that one.
There it was just creating an Array of Chart Objects and a struct to store the corner values
Resize the Rectangel Array in the beginning and upon a certain contition Create the Rectangle and ++ the Array dynamically so it doesn't run out of range.
What about the good old Keep It Stupid Simple? Do I just not get it or is consistency getting lost between the lines of C++, Alglib and MQL?!?
Or do I somehow need CArrayObj here to be able to store the double Arrays in an array of type CArrayDouble?
UPdate: found a way to create a 2D matrix on the base of
CArrayDouble matrixDouble[]; int rows = 4; int cols; = 4; ArrayResize(matrixDouble,rows); // So each double array will be one row of the matrix ('row[4]') for(int n=0 ; n<rows ; n++) { for(int m=0; m<cols ; n++) { matrixDouble[n].Add(0.0); // Thus Initializing 0.0 to each rows and column coordinate in the matrix. Why not KISS? } } //later defining void SetValue(const int n, const int m, const double v) const {m_value} //and double GetValue(const int n, const int m)
Maybe this is at least going to work like I want it to.
Yep, looks like the array operator cannot be used for assigning a value. Try the Set() method:
CMatrixDouble m(4,4); m[0].Set(0,0.5); Print("m[0][0] = ",m[0][0]);
And this does not even compile:
CMatrixDouble doubleMatrix =new *CMatrixDouble(4,4);
As a rule of thumb, use new only when you need a pointer to a dynamically allocated class instance. Any new in your code should be paired with a corresponding delete somewhere to avoid memory leaks.
Yep, looks like the array operator cannot be used for assigning a value. Try the Set() method:
And this does not even compile:
As a rule of thumb, use new only when you need a pointer to a dynamically allocated class instance. Any new in your code should be paired with a corresponding delete somewhere to avoid memory leaks.
Hey thanks, it works like that. Seems I just overcomplicated it but...
Another thing I noticed is that in the documentary example of CArrayObj what I originally wanted to do is exactly explained. But one week ago I was not nearly knowledgeable enough about the topic to realize that. Here you can actually Add() subarrays of the CArrayInt/Double etc. to an Array of Objects, since all the classes in MQL basically inherit the base class CObject. Then you probably have to watch out for memory allocation as you mentioned. This is exciting! I am going to take over the internet soon and all your phones will be ringing at the same time...
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So there is this include Math/Alglib/matrix.mqh in which you find the methods for setting the height and width of a matrix, but I can't find where to just place values inside a given place in a matrix or where can I read values from a matrix?