필터 지우기
필터 지우기

OOP subsref runs twice with "end"?

조회 수: 1 (최근 30일)
matt dash
matt dash 2014년 10월 20일
편집: Matt J 2014년 10월 20일
I have a simple object:
classdef objTest
methods
function [varargout]=subsref(obj,S)
disp(S)
varargout={[]}; %irrelevant for this test...
end
end
end
Now if I do o = objTest; o.test{1}(1:end), it displays S twice, first showing only the . and {} references, and then again showing all 3. Can anyone explain why this happens? I assume it's somehow related to a builtin function running to figure out how to evaluate the "end"?

채택된 답변

Matt J
Matt J 2014년 10월 20일
편집: Matt J 2014년 10월 20일
I assume it's somehow related to a builtin function running to figure out how to evaluate the "end"?
Yes. The expression o.test{1}(1:end) is equivalent to
temp=o.test{1};
n=numel(temp);
o.test{1}(1:n);
So, subsref is called twice. If you had done o.test{end}(1:end), then it would have been called three times.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by