cant get object's method to return multiple outputs
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
Hi, i cant get my method to return multiple outputs. 
I have my object folder with the classdef
classdef crm < handle
 %...
    methods (Access = public)     
        [Tout,Yout]=runTimeDependent(self,n_0,tdata,nedata,Tedata)
    end
end
And my function definition in a separate file inside the @crm folder
function [Tout,Yout]=runTimeDependent(self,n_0,tdata,nedata,Tedata)
    TSPAN = [tdata(1) tdata(end)];
    [Tout,Yout]=ode15s(@odefun,TSPAN,n_0);
    function dydt=odefun(t,y)
        % ... ode function here
    end
end
If i build my object and run the method everything works but if i ask 2 outputs i get an error
c=crm();
% definemy parameters ( Y0, t, ne, Te)
c.runTimeDependent(Y0,t,ne,Te); % This line works
[Tout, Yout] = c.runTimeDependent(Y0,t,ne,Te); %this line throws an error
Only when i ask both my outputs do i get an error
Error using indexing
Too many output arguments.
Error in test_timedep (line 4)
[Tout, Yout] = c.runTimeDependent(Y0,t,ne,Te);
댓글 수: 2
  Walter Roberson
      
      
 2025년 1월 28일
				
      편집: Walter Roberson
      
      
 2025년 1월 28일
  
			It would be interesting to see the output of
[Tout, Yout] = runTimeDependent(c,Y0,t,ne,Te);
and of
[Tout] = c.runTimeDependent(Y0,t,ne,Te);
채택된 답변
  Steven Lord
    
      
 2025년 1월 29일
        From the error message I suspect the class overloads indexing, either by overloading subsref or using one or more of the indexing mixins (specifically the matlab.mixin.indexing.RedefinesDot Class). Is that correct? If so, does the class overload either of the methods dotListLength or dotReference or does it inherit from either of the classes   matlab.mixin.indexing.ForbidsPublicDotMethodCall, or matlab.mixin.indexing.OverridesPublicDotMethodCall method to handle the case where the "reference" is actually a call to a class method?
댓글 수: 2
  Steven Lord
    
      
 2025년 1월 30일
				Set a breakpoint in that function then run this command:
[Tout] = c.runTimeDependent(Y0,t,ne,Te);
You should see that MATLAB will stop at the breakpoint in the class's subsref method.
Your subsref should probably be implemented with varargout as an output argument, and when subsref invokes one of the class's methods it should use the technique shown in the "Assigning to a Comma-Separated List" section on this documentation page. You may also need to overload the numArgumentsFromSubscript method; see the second example on that documentation page for an example of a class that both overloads that method and has a subsref overload returning varargout.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


