"Steven_Lord" <slord@mathworks.com> wrote in message <ko83qf$4fo$1@newscl01ah.mathworks.com>...
>
>
> "kj" <no.email@please.post> wrote in message
> news:ko7tn0$5n$1@reader1.panix.com...
> >
> > I'm very new to MATLAB, but AFAIK, the following syntax is
> > categorically disallowed:
> >
> > A = foo(B)(1);
> >
> > Here foo is some function. Ditto if one replaces (1) with any
> > other indexing subexpression (e.g. {42:end, 'frobozz'}, etc.).
>
> Correct, it is disallowed. In languages that only allow functions to return
> one output argument, that type of syntax may make sense. But functions in
> MATLAB can return multiple outputs; if that syntax were allowed, what would
> you expect this to return?
>
> [maxValues, maxLocations] = max(magic(5))(3)
>
> Should it return the third element of each of the regular outputs from MAX?
> Should it only apply to maxValues and return all of maxLocations from the
> MAX call? What about cases where the function output arguments are different
> sizes?
>
> [R, p] = chol(magic(6))(:, 2)
>
> If you execute:
>
> [R, p] = chol(magic(6))
>
> In this case, R should be a 2-by-2 matrix and p should be the 1-by-1 scalar
> 3. [The second output, p, is ALWAYS a scalar.] So asking for the second
> column of R makes sense, but asking for the second column of the scalar p
> does not and would error. We could probably invent some syntax to allow
> different indexing into different outputs of the function, but it would
> probably be difficult to read due to its generality.
>
(snip)
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Steve, it seems to me that the most handy/requested use case would be to allow indexing of single-output functions, and then just error out if an index is supplied and multiple outputs are requested. Would that be possible? It would probably satisfy the majority of people's desire for this type of functionality - as you say, adding new syntax to indicate indexing into multiple outputs would probably be confusing. Of course I'd think it would still be desirable to be able to do something like this: [~, maxLocations] = max(magic(5))(3)
Cheers
>
>
> "kj" <no.email@please.post> wrote in message
> news:ko7tn0$5n$1@reader1.panix.com...
> >
> > I'm very new to MATLAB, but AFAIK, the following syntax is
> > categorically disallowed:
> >
> > A = foo(B)(1);
> >
> > Here foo is some function. Ditto if one replaces (1) with any
> > other indexing subexpression (e.g. {42:end, 'frobozz'}, etc.).
>
> Correct, it is disallowed. In languages that only allow functions to return
> one output argument, that type of syntax may make sense. But functions in
> MATLAB can return multiple outputs; if that syntax were allowed, what would
> you expect this to return?
>
> [maxValues, maxLocations] = max(magic(5))(3)
>
> Should it return the third element of each of the regular outputs from MAX?
> Should it only apply to maxValues and return all of maxLocations from the
> MAX call? What about cases where the function output arguments are different
> sizes?
>
> [R, p] = chol(magic(6))(:, 2)
>
> If you execute:
>
> [R, p] = chol(magic(6))
>
> In this case, R should be a 2-by-2 matrix and p should be the 1-by-1 scalar
> 3. [The second output, p, is ALWAYS a scalar.] So asking for the second
> column of R makes sense, but asking for the second column of the scalar p
> does not and would error. We could probably invent some syntax to allow
> different indexing into different outputs of the function, but it would
> probably be difficult to read due to its generality.
>
(snip)
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Steve, it seems to me that the most handy/requested use case would be to allow indexing of single-output functions, and then just error out if an index is supplied and multiple outputs are requested. Would that be possible? It would probably satisfy the majority of people's desire for this type of functionality - as you say, adding new syntax to indicate indexing into multiple outputs would probably be confusing. Of course I'd think it would still be desirable to be able to do something like this: [~, maxLocations] = max(magic(5))(3)
Cheers