1

Here is my code:

f.m:

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 s t;
[n d] = numden(f.x); % 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));

When I type test in the command window, it tells me the following:

>> test
??? The property 'x' in class 'f' must be accessed from a class instance because it
is not a Constant property.
chappjc
  • 30,359
  • 6
  • 75
  • 132
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • Like it says, you need to create the object f first, and write an accessor method to return the value of x. – Alex Mar 07 '11 at 04:23
  • @Alex How to define the accessor method? and where should I create the object f, in test.m? last thing, how to call the method then? – Eng.Fouad Mar 07 '11 at 05:09

1 Answers1

3

As Alex points out, you need an instance of f to access the member property x, like so:

myf = f();
f.x

You do not need an accessor method to get at x as it is defined as a public property. If you chose to make x private, then you'd need an accessor method something like this:

function x = getX( obj )
  x = obj.x;
end
Edric
  • 23,676
  • 2
  • 38
  • 40