For whatever reason, Matlab does not allow repeating round brackets () - the iterator. This blocks direct access to outputs of functions which are multidimensional array and makes dictionary object immutable, among other applications.
For example,
func1=@(x)[sin(x);cos(x)];
% let S be some large struct where everything is stored
func2=@(str)S.(str);
% let D be some containers.Map object where everything is stored
D(key)=[1;2];
In all of the 3 cases above, it is useful to be able to access the array elements directly. But any of
func1(Pi)(i); func2(f1)(i); D(key)(i)
will result in the error
()-indexing must appear last in an index expression.
Is there anyway around this besides creating a temporary variable?
As well, if your answer is that temporary variable is the ONLY way to go, would you kindly show me whether the creation of a second variable will result in duplication of the data in memory?