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

 
So how do you get a column out of a matrix?
 
Aleksey Vyazmikin #:

It's not a vector, it's a matrix, I have the code above

You have to figure it out yourself or convince the compiler. See examples, read.


 
Aleksey Vyazmikin #:
So how do you get a column out of a matrix?

You can get a vector from a matrix using Col

What do you mean by "pull out"? Remove?

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

You can get a vector from a matrix using Col

What do you mean by "take out"? Remove?

Take it out in terms of converting it into something to work with.

I showed above the code that I failed with Col, it was a matrix, not a vector, as you wrote.

 
You need to rest and re-read all your questions in this discussion tomorrow.
 
Rashid Umarov #:
You need to rest and re-read all your questions in this osbud tomorrow

Thank you for your concern!

Most of the questions have been resolved with your help.

I will wait until tomorrow, maybe you can answer my question later.

 
Rashid Umarov #:

No one reads it, but they're willing to support it. I thought I saw you in the machine learning thread? If so, you should understand what is written in the article.

I guess I don't fully understand. Why a matrix element has 3 values. It's a 3-dimensional array. Why in the help the vector is a one-dimensional array and the matrix in this example is represented by a three-dimensional one.
ZY, it happens)))) in the example there are 3 rows and 4 columns)))) matrix))))))
 

There's probably a little mistake here:

//--- matrix copying
  matrix a= {{2, 2}, {3, 3}, {4, 4}};
  matrix b=a+2;
  matrix c;
  Print("matrix a \n", a);
  Print("matrix b \n", b);
  c.Assign(b);
  Print("matrix c \n", a);
  /*
matrix a
[[2,2]
[3,3]
[4,4]]
matrix b
[[4,4]
[5,5]
[6,6]]
 matrix c
 [[2,2]
 [3,3]
 [4,4]]
  */

It should be like this:

//--- matrix copying
  matrix a= {{2, 2}, {3, 3}, {4, 4}};
  matrix b=a+2;
  matrix c;
  Print("matrix a \n", a);
  Print("matrix b \n", b);
  c.Assign(b);
  Print("matrix c \n", с);
  /*
matrix a
[[2,2]
[3,3]
[4,4]]
matrix b
[[4,4]
[5,5]
[6,6]]
 matrix c
 [[4,4]
 [5,5]
 [6,6]]
  */
 

Another minor error in the section"Copying timeseries to matrix or vector":

//--- list of characters to be calculated
  string symbols[]= {"EURUSD", "GBPUSD", "USDJPY", "USDCAD", "USDCHF"};
  int size=ArraySize(symbols);
//--- matrix and vector to get prices Close
  matrix rates(InBars, size);
  vector close;
  for(int i=0; i<size; i++)
   {
    //--- get Close prices into vector
    if(close.CopyRates(symbols[i], InTF, COPY_RATES_CLOSE, 1, InBars))
     {
      //--- insert the vector into the timeseries matrix
      rates.Col(close, i);
      PrintFormat("%d. %s: %d Close prices added to the matrix.", i+1, symbols[i], close.Size());
      //--- output the first 20 values of the vector for debugging
      int  digits=(int)SymbolInfoInteger(symbols[i], SYMBOL_DIGITS);
      Print(VectorToString(close, 20, digits));
     }
    else
     {
      Print("vector.CopyRates(%d,COPY_RATES_CLOSE) failed. Error ", symbols[i], GetLastError());
      return;
     }
   }

Probably better like this:

//--- list of characters to be calculated
   string symbols[] = {"EURUSD", "GBPUSD", "USDJPY", "USDCAD", "USDCHF"};
   int size =::ArraySize(symbols);
//--- matrix and vector to get prices Close
   matrix rates_mx(InBars, size);
   vector close_vc;
   for(int i = 0; i < size; i++)
      {
      ::ResetLastError();
      //--- get Close prices into vector
      if(close_vc.CopyRates(symbols[i], InTF, COPY_RATES_CLOSE, 1, InBars))
         {
         //--- insert the vector into the timeseries matrix
         rates_mx.Col(close_vc, i);
         ::PrintFormat("%d. %s: %d Close prices added to the matrix.", i + 1, symbols[i],close_vc.Size());
         //--- output the first 20 values of the vector for debugging
         int  digits = (int)::SymbolInfoInteger(symbols[i], SYMBOL_DIGITS); ::Print(VectorToString(close_vc, 20, digits));
         }
      else
         {
         ::PrintFormat("vector.CopyRates(%s,COPY_RATES_CLOSE) failed. Error %d", symbols[i], ::GetLastError());
         return;
         }
      }
 
Denis Kirichenko #:

There 's probably a little mistake here:

It should be like this:

Thank you, corrected