Discussion of article "Matrix and Vector operations in MQL5" - page 2

 
Rashid Umarov #:
There is, read the article .

The article copies a multidimensional array, but you need a one-dimensional one!

 
Hi all. I want to study the indicator but I don't know where to start.
 

I don't understand why you can't just help, show an example - that's what the article discussion is for - sad.

In general, I decided that only through a vector it is possible - to pass an array there, and then screw it to a matrix, but so far I have not even got to the point of how to bend it (from a vector it is possible to make a matrix with a specified number of columns, as if transforming it?), and not the fact that it is possible, so I got a crash.

2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      Access violation at 0x0000000140D77E04 write to 0x00000002CBD3617E
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)         crash -->  0000000140 D77E04 6644896473 FE      mov        [rbx+rsi*2-0x2], r12w
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E0A 83 F8FE            cmp        eax, 0xfe
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E0D 751 C              jnz        0x140d77e2b
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E0F 4 C3BF7            cmp        r14, rdi
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E12 751 B              jnz        0x140d77e2f
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E14 443865 F0          cmp        [rbp-0x10], r12b
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)                    0000000140 D77E18 7478              jz         0x140d77e92
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      00: 0x0000000140D77E04
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      01: 0x00000001403246C7
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      02: 0x0000000140BCBBC8
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      03: 0x0000000140BCBA81
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      04: 0x0000000140BCB78B
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      05: 0x0000000140BB848B
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      06: 0x0000000140BBA5D1
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      07: 0x0000000140BBA491
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      08: 0x00000000040E06D0
2022.10.08 06:12:48.942 Test_Matrix_02 (EURUSD,H1)      

I am attaching the code of course

//+------------------------------------------------------------------+
//|Test_Matrix_02.mq5 |
//|Copyright 2022, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
   matrix target;
   int count=1000;
   target.Init(count, 1);
   vector V_Target;//Vector to get an array with targets and transfer it to a matrix
   int arr_Target[];
   ArrayResize(arr_Target,count);
   int T_Rand=0;//We'll write a random
   for(int i=0; i<count; i++)
     {
     T_Rand=rand();
     if(T_Rand>32767/2)arr_Target[i]=1;
     else arr_Target[i]=0;
     }
   V_Target.Assign(arr_Target);
   if(!target.Col(V_Target,0))
   return ;
   Print("data after Col(V_Target) \n", target);
   
  }
//+------------------------------------------------------------------+
 

Alexei, everything works for me. Here is your script, slightly tweaked:

//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
   const int count = 20;
   ::MathSrand(1);
//--- array
   int target_arr[];
   ::ArrayResize(target_arr, count);
   for(int i = 0; i < count; i++)
     {
      int T_Rand = ::MathRand();
      if(T_Rand > 32767 / 2)
         target_arr[i] = 1;
      else
         target_arr[i] = 0;
     }
//--- vector
   vector target_vc;
   target_vc.Assign(target_arr);
//--- matrix
   matrix target_mx(count, 1);
   if(!target_mx.Col(target_vc, 0))
      return;
   ::Print("data after Col(target_vc) \n", target_mx);
   int rows, cols;
   rows = 4;
   cols = 5;
   if(!target_mx.Reshape(rows, cols))
      return;
   ::Print("data after Reshape \n", target_mx);
  }
//+------------------------------------------------------------------+


Log:

2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)        data after Col(target_vc) 
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)        [[0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0]]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)        data after Reshape 
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)        [[0,1,0,1,1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0,0,1,1,1]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0,1,1,1,0]
2022.10.08 20:48:55.335 Test_Matrix_02 (SBER,H1)         [0,0,0,0,0]]
 
Denis Kirichenko #:

Alexei, everything works for me. Here is your script, slightly tweaked:


Log:

Thank you. Yes, I know that the /n in the print causes the crash, but I don't know what the ":" means.

Thanks for the matrix transfer - I read it this morning, but I haven't tried it. But it turns out still a lot of memory will be consumed - let's say we collected data in a one-dimensional array, then we need to put it into a vector, then into a matrix - already 3 repeated entities, which is not good. Why can't we immediately transfer a one-dimensional array into a matrix?

 

I can't understand:

1. How to transfer a matrix into an array

2. How to read a specific value in the matrix and how to write it with the indication of row and column

I have read the article more than once - maybe I don't understand the wording in it, but here is the fact - there are questions.

 
Aleksey Vyazmikin #:

Thank you. Yes, I know that /n in the print causes the crash, but I don't know what ":" means.

Thanks for the matrix transfer - I read it this morning, but I haven't tried it. But it turns out still a lot of memory will be consumed - let's say we collected data in a one-dimensional array, then we need to put it into a vector, then into a matrix - already 3 repeated entities, which is not good. Why can't we immediately transfer a one-dimensional array into a matrix?

I don't know, I guess the Developer knows better.... Why can't you immediately collect data into a matrix, bypassing the chain "array-vector-matrix" ? ))

 
Denis Kirichenko #:

I don't know, perhaps the Developer knows better.... Why can't you just collect data into a matrix, bypassing the "array-vector-matrix" chain ? ))

So far I don't understand how to fill the matrix directly by cells and how to read from it.

In general, I read data from bin file into array - it is a sample - I wanted to work with it as with a matrix, I think there was an opportunity in the beginning to read a matrix from the file, but now I do not see such an opportunity in the instructions.

Документация по MQL5: Методы матриц и векторов
Документация по MQL5: Методы матриц и векторов
  • www.mql5.com
Методы матриц и векторов - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Aleksey Vyazmikin #:

So far I don't understand how to cell-by-cell fill the matrix directly and how to read from it.

See the example about matrix multiplication in OpenCL

 
Or search the MatrixSetValues article, everything is in plain sight.