25 thoughts on “Matlab pls

  1. https://en.wikibooks.org/wiki/Ada_Programming/Types/array

    Would you like an array that goes from -10 to 351? Ada can do that.

  2. Here’s the key difference: array indices in normal programming languages are offsets, not ordinals. `Array[0]` does not mean the “zeroth” element, but rather that it’s the element with 0 offset from the beginning. It’s still the “first”. This started in very low-level languages for which this abstraction makes sense, and it became the norm for later programming languages simply by convention. It’s what makes sense for *us programmers*.

    Indices in *mathematial* languages, on the other hand, *are* ordinals. Since these languages are targeted toward people outside our field, and don’t really care about memory layout, there’s no reason to stick to the “[0] is first element” convention. It’s much easier to teach someone that index 1 is element 1, 2 is 2, 3 is 3, and so forth.

    tl;dr: for `array[n]`, n is an offset in C, or an ordinal in math languages.

  3. Math is probably the most natural language ever invented (or discovered?). Going by natural language logic, the first element is usually the 1st, not the 0th. But how boring would life be without layers of indirection. 😉

  4. I like to think of the index like a birthday. The day you are born (technically your first birthday) you are 0. So the first index is 0.

  5. My actual reaction using a system or language or whatever where arrays start at 1: “Oh OK, fair enough”.

  6. Tell me if im wrong but cant you make arrays in Pascal start at any number or even character?
    So a for loop would look like this, FOR char i := ‘a’; i < ‘z’; i++DO or something like rhat

  7. I’m actually in a Matlab class right now for my physics major and, coming from a computer science major, I’ve had to really adjust to it. First day we went over arrays and the prof was typing an array call and used one to call the first index and it blew my mind.

Leave a Reply

Your email address will not be published. Required fields are marked *