I am getting an error "cannot convert double value to a handle".

31 次查看(过去 30 天)
classdef MAIN < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
PrincipleEditFieldLabel matlab.ui.control.Label
PrincipleAmount matlab.ui.control.NumericEditField
RateEditFieldLabel matlab.ui.control.Label
numInterestRate matlab.ui.control.NumericEditField
TimescompoundedEditFieldLabel matlab.ui.control.Label
PeriodYears matlab.ui.control.NumericEditField
TimeyearsEditFieldLabel matlab.ui.control.Label
Timeyears matlab.ui.control.NumericEditField
CalculateButton matlab.ui.control.Button
TotalEditFieldLabel matlab.ui.control.Label
TotalInvestment matlab.ui.control.NumericEditField
end
methods (Access = private)
% Code that executes after component creation
end
methods (Access = private)
% Button pushed function: CalculateButton
function CalculateButtonPushed(app, event)
% Calculate the monthly payment
Amount = app.PrincipleAmount.Value ;
Rate = app.numInterestRate.Value;
nper = app.PeriodYears.Value ;
Time = app.Timeyears.Value;
app.TotalInvestment = Amount*(1 + ((Rate*1/100)/nper))^(nper*Time)
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create PrincipleEditFieldLabel
app.PrincipleEditFieldLabel = uilabel(app.UIFigure);
app.PrincipleEditFieldLabel.HorizontalAlignment = 'right';
app.PrincipleEditFieldLabel.Position = [66 384 53 15];
app.PrincipleEditFieldLabel.Text = 'Principle';
% Create PrincipleAmount
app.PrincipleAmount = uieditfield(app.UIFigure, 'numeric');
app.PrincipleAmount.Position = [134 380 100 22];
% Create RateEditFieldLabel
app.RateEditFieldLabel = uilabel(app.UIFigure);
app.RateEditFieldLabel.HorizontalAlignment = 'right';
app.RateEditFieldLabel.Position = [88 347 31 15];
app.RateEditFieldLabel.Text = 'Rate';
% Create numInterestRate
app.numInterestRate = uieditfield(app.UIFigure, 'numeric');
app.numInterestRate.Position = [134 343 100 22];
% Create TimescompoundedEditFieldLabel
app.TimescompoundedEditFieldLabel = uilabel(app.UIFigure);
app.TimescompoundedEditFieldLabel.HorizontalAlignment = 'right';
app.TimescompoundedEditFieldLabel.Position = [6 308 113 15];
app.TimescompoundedEditFieldLabel.Text = 'Times compounded';
% Create PeriodYears
app.PeriodYears = uieditfield(app.UIFigure, 'numeric');
app.PeriodYears.Position = [134 304 100 22];
% Create TimeyearsEditFieldLabel
app.TimeyearsEditFieldLabel = uilabel(app.UIFigure);
app.TimeyearsEditFieldLabel.HorizontalAlignment = 'right';
app.TimeyearsEditFieldLabel.Position = [49 268 70 15];
app.TimeyearsEditFieldLabel.Text = 'Time(years)';
% Create Timeyears
app.Timeyears = uieditfield(app.UIFigure, 'numeric');
app.Timeyears.Position = [134 264 100 22];
% Create CalculateButton
app.CalculateButton = uibutton(app.UIFigure, 'push');
app.CalculateButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);
app.CalculateButton.Position = [19 162 100 22];
app.CalculateButton.Text = 'Calculate';
% Create TotalEditFieldLabel
app.TotalEditFieldLabel = uilabel(app.UIFigure);
app.TotalEditFieldLabel.HorizontalAlignment = 'right';
app.TotalEditFieldLabel.Position = [135 166 35 15];
app.TotalEditFieldLabel.Text = 'Total ';
% Create TotalInvestment
app.TotalInvestment = uieditfield(app.UIFigure, 'numeric');
app.TotalInvestment.Position = [185 162 100 22];
end
end
methods (Access = public)
% Construct app
function app = MAIN()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

回答(1 个)

Eric Delgado
Eric Delgado 2022-9-19
You forgot to put the value in the property "Value" of the object...
app.TotalInvestment.Value = Amount*(1 + ((Rate*1/100)/nper))^(nper*Time)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by