Direct cell {} indexing of class method output

Over the years, I've seen lots of posts (like this one) asking whether it is possible to append indexing operators to a function call, so as to extract partial contents from the function's output in a single command. The stock answer is that such syntax is not allowed. Lately however (R2017b), I have noticed that this is possible when a class method returns a cell array. Take the following class as an example,
classdef myclass
methods
function c=foo(obj)
c={pi,exp(1),1i};
end
end
end
I find that I can do the following kinds of post-indexing, which I reason shouldn't be allowed, since foo() is a function call, and not a class property
>> obj=myclass;
>> obj.foo{1}
ans =
3.1416
>> obj.foo{1:2}
ans =
3.1416
ans =
2.7183
My question is, has this always been possible? Is it documented anywhere?

 채택된 답변

James Tursa
James Tursa 2018년 6월 7일

1 개 추천

Spot checking: Works in R2009a 32-bit and R2018a 64-bit, so I would presume it has always worked although I have not tested everything in between.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

질문:

2018년 6월 7일

답변:

2018년 6월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by