How do I access the 0th dimension of an array?

 

I actually avoid coming here, but I've spent 90 minutes trying to solve this big mystery with no success because the documentation absolutely does not help and all examples I find are very complex, seemingly going out of their way to avoid the simple.

int Numbers [20][1];

   Numbers[0] = 100110010;
   Numbers[0][1] = 200220020;


The first variable assignment line causes an error. I can't understand why.

The second variable assignment line is correct. But that will assign "200220020" to [0][1]. And what is [0]? How do I assign just [0]?

I also need to iterate over the 0th dimension so I need to get [0] alone.

What_I_Want = Numbers[0];
if (What_I_Want == What_I_Really_Want) {OK_Lets_Proceed();}

Whenever I try accessing the 0th dimension alone, I get errors. MQL4 wants both indexes. But I just want to check the 0th dimension. It seems the 0th dimension is completely out of my reach. I can only set and access the 1st dimension. That amounts to a one-dimension array.

What I really want is an Array Search mechanism.

int ArraySearch(string array, int ticket) {
   for (int i=0; i <= ArraySize(array) - 1; i++)   {
      if (array[i] == ticket)   {return i;}
   }
   return -1;
}

I made it because MQL4 doesn't have it. ArrayBsearch "returns index of a found element. If the wanted value isn't found, the function returns the index of an element nearest in value." The "element nearest in value" doesn't really do what I need. I need either an absolutely accurate index or -1 or something that tells me the array element doesn't exist. I won't even try to understand why someone thought that returning an incorrect value just because it is "nearest in value" was a good idea.

So how do I set and access the 0th dimension?

Note: structs won't do. I need something I can search. i.e. I need to be able to iterate over it.

Thank you for any attention.

Documentation on MQL5: Language Basics / Variables
Documentation on MQL5: Language Basics / Variables
  • www.mql5.com
Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
whoowl:

I actually avoid coming here, but I've spent 90 minutes trying to solve this big mystery with no success because the documentation absolutely does not help and all examples I find are very complex, seemingly going out of their way to avoid the simple.


The first variable assignment line causes an error. I can't understand why.

The second variable assignment line is correct. But that will assign "200220020" to [0][1]. And what is [0]? How do I assign just [0]?

I also need to iterate over the 0th dimension so I need to get [0] alone.

Whenever I try accessing the 0th dimension alone, I get errors. MQL4 wants both indexes. But I just want to check the 0th dimension. It seems the 0th dimension is completely out of my reach. I can only set and access the 1st dimension. That amounts to a one-dimension array.

What I really want is an Array Search mechanism.

I made it because MQL4 doesn't have it. ArrayBsearch "returns index of a found element. If the wanted value isn't found, the function returns the index of an element nearest in value." The "element nearest in value" doesn't really do what I need. I need either an absolutely accurate index or -1 or something that tells me the array element doesn't exist. I won't even try to understand why someone thought that returning an incorrect value just because it is "nearest in value" was a good idea.

So how do I set and access the 0th dimension?

Note: structs won't do. I need something I can search. i.e. I need to be able to iterate over it.

Thank you for any attention.

This is due to the nature of addressing the content of the array, the first dimension is "virtual" and does not exist in that sense.

If you look at it from the memory perspective, you will understand why.

It works (simplified) like this:

Multiply the size of first dimension with size of second dimension. You get the max elements.

Since all elements are (like in Excel) in one column, you have the (in your case, where the second dimension is size 2) first element of the second dimension in odd rows, and the second element in the even rows.

As you can see, there is no room for the "zeroth" dimension.

That's how it works in the physical memory. (Simplified)

Edit:
This is not limited to MQL, but all actual programming languages that work with physical representation.
 
Thank you for your reply.
But I still have no idea of how to work with the 0th dimension.
How do I set or access Numbers[0]?
I can imagine someone searching for that information just like I did today and not finding a simple, straightforward, practical example just like I didn't today.

So are you telling me the 0th dimension is completely useless and I have to do this?
int Numbers [][20][1];

   Numbers[0][0] = 100110010;
   Numbers[0][0][1] = 200220020;
 
whoowl #:
Thank you for your reply.
But I still have no idea of how to work with the 0th dimension.
How do I set or access Numbers[0]?
I can imagine someone searching for that information just like I did today and not finding a simple, straightforward, practical example just like I didn't today.

So are you telling me the 0th dimension is completely useless and I have to do this?
You should google multi dimensional arrays and learn the basics

An array of [10][10]. Is 100 elements their is no first element without the second part only 10 rows of 10 elements 
 

Paul Anscombe #:
You should google multi dimensional arrays and learn the basics


Well,

whoowl:

I've spent 90 minutes trying to solve this big mystery with no success because the documentation absolutely does not help and all examples I find are very complex, seemingly going out of their way to avoid the simple.


Paul Anscombe #:
An array of [10][10]. Is 100 elements their is no first element without the second part only 10 rows of 10 elements 

And how was the first [10] in [10][10] created?
How is that created or accessed?

See how adamantly mysteriously mysterious this thing is?
No wonder there are no practical examples to be found. It's like some sort of taboo.

 
whoowl #: And how was the first [10] in [10][10] created? How is that created or accessed?

[10][10} means 10 x 10 = 100, addressed in the following way

[0}[0], [0}[1], [0][2] ... [0][8], [0][9], [1][0], [1][1], [1][2] ...  [1][8], [1][9], [2][0], [2][1], [2][2], ... ... [8][8], [8][9], [9][0], [9][1], [9][2] ... [9][8], [9][9]

// Simple example (uncompiled, untested, simply typed out)

int naSquare[10][10];

for( int i = 0; i < 10; i++ )
   for( int j = 0; j < 10; j++ )
      naSquare[i][j] = i * 10 + j;
 
whoowl #:


Well,


And how was the first [10] in [10][10] created?
How is that created or accessed?

See how adamantly mysteriously mysterious this thing is?
No wonder there are no practical examples to be found. It's like some sort of taboo.

Try this 
Files:
IMG_5523.jpeg  241 kb
 
So I have a list of ticket numbers, I select their orders by ticket number and I collect their respective magic numbers.
How do I store that information in an array?
How do I build
Array[ticket][magic]?
Array[1100101][2200202]?

I lnow how to query/select orders and collect their data. I need the syntax for inserting that data into an array.
 
whoowl #:


Well,


And how was the first [10] in [10][10] created?
How is that created or accessed?

See how adamantly mysteriously mysterious this thing is?
No wonder there are no practical examples to be found. It's like some sort of taboo.

No...

If you multiply 10 cakes by 2. You get 20 cakes.

But you don't need 2 cakes to multiply the 10 cakes. The 2 is virtual...

You do not end up with 22 cakes. It doesn't work that way.

Dimensions of an array are simply said multipliers. Only the last dimension has actually memory associated to it.

As I initially said, it is just one column.

Or, another example. Let's say you have a pack of papers. And you put a second pack of paper on top, you do not get 2 packs of paper plus 2 sheets of paper. Where should they come from??

Multidimensional arrays are simply said just a division of the total element count.

Let's say you have an array with 100 elements. You could address them either in one dimension [0 ... 99] or as [0 ... 1][0 ... 49] or as [0 ... 9][0 ... 1][0 ... 4]

As you see, if you remove one of the dimensions, like in the last example, [9][1] omitting the last dimension, a multiplier is now missing... This will not give you a valid count.

PS: Actually, in C/C++ with pointer arithmetic, you can do it, but you would, when doing this: [9][1] what actually would happen is this: [9][1][0]

But only because you "tricked" the compiler with your own pointer arithmetic, overwriting the internal one.
 
whoowl #: See how adamantly mysteriously mysterious this thing is? No wonder there are no practical examples to be found. It's like some sort of taboo.

There is no taboo. There is no mystery. This is simple maths. A 2D array is a simple table (spreadsheet, chess board, soduko square, etc.)

1D array is a vector, a 2D array is a matrix, ... can be extended to more dimensions ...  3D, 4D , etc.

 
OK.

So I have a list of ticket numbers, I select their orders by ticket number and I collect their respective magic numbers.
How do I store that information in an array?
How do I build
Array[ticket][magic]?
Array[1100101][2200202]?

I've learned that Numbers[0] = 100110010; doesn't work.
What syntax would work?
Reason: