![]() |
在另一个.m文件中使用classdef的属性?
这是我的代码:
调频: classdef f < handle properties (Access = public) functionString = ''; x; end methods function obj = f if nargin == 0 syms s; obj.x = input('Enter your function: '); obj.functionString = ilaplace(obj.x); end end function value = subsref(obj, a) t = a.subs{:}; value = eval(obj.functionString); end function display(obj) end end end test.m: syms st; [nd] = numden(fx); % Here I want to use x, which is the user input, How can I do such thing? zeros = solve(n); poles = solve(d); disp('The Poles:'); disp(poles); disp('The Zeros:'); disp(zeros); disp('The Result:'); disp(z(t)); disp('The Initial Value:'); disp(z(0)); disp('The Final Value:'); disp(z(Inf)); 当我在命令窗口中键入test时,它会告诉我以下内容: >> test ??? The property 'x' in class 'f' must be accessed from a class instance because it is not a Constant property. [B]回答:[/B] 正如Alex指出的那样,您需要f的实例才能访问成员属性x ,如下所示: myf = f(); fx 由于x被定义为公共属性,因此不需要访问器方法即可到达x 。如果您选择将x设为私有,那么您将需要一个类似于以下内容的访问器方法: function x = getX( obj ) x = obj.x; end [url=https://stackoverflow.com/questions/5215747]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 14:47。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.