0

I found the question How can I index a MATLAB array returned by a function without first assigning it to a local variable? in an attempt to figure out why I was getting errors with indexing a value returned by the containers.Map function until I used a local variable, but I still don't really understand what's actually going on. From the answers to that question, I can see that the most readable way to index data structures returned by functions is to just use a temporary variable. But my question is why it's invalid to do something like this:

letters = {'a', 'b', 'c', 'd'};
voltages = {{1.8, 1}, {0.7, 1.5}, {1.8, 0.1}, {1.8*, 1.8}};
VGS_VDS_dict = containers.Map(letters, voltages);

temp = (VGS_VDS_dict('a')){1}

But perfectly fine to do

temp1 = (VGS_VDS_dict('a'));
temp2 = temp1{1}

?

What is it about the grammar of MatLab that makes the first example invalid but not the second one?

  • 4
    It’s a choice made by the developers. Octave copies MATLAB syntax but allows indexing the return value of a function. There is no technical limitation. So only the MATLAB developers can answer this question, it’s not really something that we can answer here. – Cris Luengo Aug 28 '23 at 03:04
  • @CrisLuengo, so there's nothing about the grammar of the language that requires it to be that way? It's just an artificially imposed limitation? – Mikayla Eckel Cifrese Aug 28 '23 at 06:53
  • Indeed, I don't think there's a technical limitation. Maybe they think it would make harder to read? – Cris Luengo Aug 28 '23 at 07:07
  • @MikaylaEckelCifrese What's the difference between the grammar of the language and an artificially imposed limitation? All grammars are artificially imposed limitations. Obviously it's technically possible though, because Octave allows it. – beaker Aug 28 '23 at 15:57
  • @beaker, I mean, is there some larger design design design decision it's a result of, such that changing it would require also making other changes? Or is it an "extra" (for lack of a better word) imposed limitation independent of other design decisions? – Mikayla Eckel Cifrese Aug 29 '23 at 08:38
  • 1
    Hm. Well, as I said, Octave does it so it's feasible. Mathworks was also slow to adopt implicit broadcast that Octave had for years. fwiw, the MATLAB grammar definition is available [on github](https://github.com/mathworks/MATLAB-Language-grammar). – beaker Aug 29 '23 at 13:57

0 Answers0