MATLAB gui代码中对象的引用依赖属性

时间:2016-03-10 23:19:52

标签: matlab oop user-interface properties

我有一个LaunchSimulation类,它有一些依赖属性,每当引用属性时都需要计算它们。我试图在我的GUI文件的按钮回调中访问这些属性。我在openingFcn中创建了我的模拟对象,并且能够很好地引用常规属性,但是当我尝试引用任何依赖属性时,它表示该字段不存在。

如何访问依赖属性?我不太确定他们为什么不存在。

以下是我的LaunchSimulation类:

 [['12', '56'], ['25', '26']]

这里是GUI文件的相关代码

OpeningFcn:

classdef LaunchSimulation < handle

    %% Constants
    properties (Constant)
        g = 9.81 % m/s^2
    end

    %% Properties
    properties
        launcher
    end

    %% Dependent Properties
    properties (Dependent)

        horizontalRange
        verticalRange
        timeOfFlight

    end

    %% Non-static Methods
    methods

        %% constructor
        function this = LaunchSimulation(launcher)
            this.launcher = launcher;
        end

        %% Launch data computation for user input values
        function computeHorizontalAndVerticalRange(this)


            this.launcher.launchVelocity = input('Enter launcher velocity: ');
            this.launcher.launchAngle = input('Enter launcher angle: ');

            DataDisplayer.displayLauncherSettingsTable(this);
            fprintf('Horizontal Range: %f \n', this.horizontalRange)
            fprintf('Vertical Range: %f \n', this.verticalRange)

        end


        %% Getters and Setters

        % horizontalRange
        function value = get.horizontalRange(this)

            value = ((this.launcher.launchVelocity)^2 * sind(2 * this.launcher.launchAngle)) / LaunchSimulation.g;

        end

        % verticalRange
        function value = get.verticalRange(this)

            value = ((this.launcher.launchVelocity^2) * sind(this.launcher.launchAngle)^2) / (2 * LaunchSimulation.g);

        end

        % timeOfFlight
        function value = get.timeOfFlight(this)

            value = ((2 * this.launcher.launchVelocity) * sind(this.launcher.launchAngle)) / LaunchSimulation.g;

        end

    end
end

这是我尝试在回调中引用依赖属性的地方:

% --- Executes just before RocketLauncherSimulationGUI is made visible.
function RocketLauncherSimulationGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to RocketLauncherSimulationGUI (see VARARGIN)

% Choose default command line output for RocketLauncherSimulationGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% Instantiate a launcher object with zeroed property values
launcher = Launcher(0,0,0,0);

% Instantiate a simulation object
simulation = LaunchSimulation(launcher);

0 个答案:

没有答案