Hi guys, I'm trying to create a multiwindow app. It's my first app but I'm taking this error. How can I solve it?

1 visualización (últimos 30 días)
mainapp1.png
mainapp2.png
  3 comentarios
Adam Danz
Adam Danz el 15 de Mayo de 2019
What are the values of app.a, app.b etc. and where do they come from? Somewhere the string "mainApp" is being passed to DialogApp() and the string should be "MainApp" instead.
ahmet emin arslan
ahmet emin arslan el 15 de Mayo de 2019
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ResultEditFieldLabel matlab.ui.control.Label
Result matlab.ui.control.NumericEditField
Button matlab.ui.control.StateButton
end
properties (Access = private)
DialogApp % Dialog box app
a = 0; % a value
b = 0; % b value
c = 0; % c value
end
methods (Access = public)
function result = calculate_product(app, a, b, c)
% Store inputs as properties
app.a = a;
app.b = b;
app.c = c;
% Calculate the product
result = (app.a*app.b)^app.c;
% Change the result field value
app.Result.Value = result;
% Re-enable the button
app.Button.Enable = 'on';
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Call calculate_product function to display an initial value
calculate_product(app, app.a, app.b, app.c)
app.Result.Value = 0;
end
% Value changed function: Button
function ButtonPushed(app, event)
% Disable button while dialog is open
app.Button.Enable = 'off';
% Open the dialog box and pass inputs
app.DialogApp = DialogApp(app, app.a, app.b, app.c);
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
% Delete both apps
delete(app.InputApp)
delete(app)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 258 361];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
% Create ResultEditFieldLabel
app.ResultEditFieldLabel = uilabel(app.UIFigure);
app.ResultEditFieldLabel.HorizontalAlignment = 'right';
app.ResultEditFieldLabel.Position = [61 271 39 22];
app.ResultEditFieldLabel.Text = 'Result';
% Create Result
app.Result = uieditfield(app.UIFigure, 'numeric');
app.Result.Position = [115 271 100 22];
% Create Button
app.Button = uibutton(app.UIFigure, 'state');
app.Button.ValueChangedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Text = 'Inputs';
app.Button.Position = [99 230 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = MainApp
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
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
that is first app
classdef DialogApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
aEditFieldLabel matlab.ui.control.Label
A matlab.ui.control.NumericEditField
bEditFieldLabel matlab.ui.control.Label
B matlab.ui.control.NumericEditField
cEditFieldLabel matlab.ui.control.Label
C matlab.ui.control.NumericEditField
CalculateButton matlab.ui.control.StateButton
end
properties (Access = private)
CallingApp % Main app object
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, MainApp, a, b, c)
% Store main app in property for CloseRequestFcn to use
app.CallingApp = mainApp;
% Update UI with input values
app.A.Value = a;
app.B.Value = b;
app.C.Value = c;
end
% Value changed function: CalculateButton
function CalculateButtonPushed(app, event)
% Call main app's public function
calculate_product(app.CallingApp, app.A.Value, app.B.Value, app.C.Value)
% Delete the dialog box
delete(app)
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
% Enable the button in main app
app.CallingApp.Button.Enable = 'on';
% Delete the dialog box
delete(app)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 218 321];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
% Create aEditFieldLabel
app.aEditFieldLabel = uilabel(app.UIFigure);
app.aEditFieldLabel.HorizontalAlignment = 'right';
app.aEditFieldLabel.Position = [81 262 25 22];
app.aEditFieldLabel.Text = 'a';
% Create A
app.A = uieditfield(app.UIFigure, 'numeric');
app.A.Position = [121 262 47 22];
% Create bEditFieldLabel
app.bEditFieldLabel = uilabel(app.UIFigure);
app.bEditFieldLabel.HorizontalAlignment = 'right';
app.bEditFieldLabel.Position = [81 230 25 22];
app.bEditFieldLabel.Text = 'b';
% Create B
app.B = uieditfield(app.UIFigure, 'numeric');
app.B.Position = [121 230 47 22];
% Create cEditFieldLabel
app.cEditFieldLabel = uilabel(app.UIFigure);
app.cEditFieldLabel.HorizontalAlignment = 'right';
app.cEditFieldLabel.Position = [81 194 25 22];
app.cEditFieldLabel.Text = 'c';
% Create C
app.C = uieditfield(app.UIFigure, 'numeric');
app.C.Position = [121 194 47 22];
% Create CalculateButton
app.CalculateButton = uibutton(app.UIFigure, 'state');
app.CalculateButton.ValueChangedFcn = createCallbackFcn(app, @CalculateButtonPushed, true);
app.CalculateButton.Text = 'Calculate';
app.CalculateButton.Position = [75 126 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = DialogApp(varargin)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
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
that is second app

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 15 de Mayo de 2019
Editada: Adam Danz el 15 de Mayo de 2019
I beleive your error is here
% Code that executes after component creation
function startupFcn(app, MainApp, a, b, c)
% Store main app in property for CloseRequestFcn to use
app.CallingApp = mainApp; % <----------------------------- HERE
Should be
app.CallingApp = MainApp; % with capital M
Make that change, save the app, close the app, restart it, and test it. If the problem persists, I'd be glad to look further.

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by