Error in app designer

43 views (last 30 days)
Vahid Abolhasannejad
Vahid Abolhasannejad on 20 Apr 2020
Commented: Zayad on 12 Dec 2023
I have faced an error in my code like it says
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
on the following statement:
% Component initialization
methods (Access = private)
It's a solid statement at the end of code and I cannot change it at all. Does anybody know how to fix this problem? since it doesn't allow me to run the program.
Thank you.
Vahid.
  8 Comments
Vahid Abolhasannejad
Vahid Abolhasannejad on 7 Apr 2021
Hello Walter, thank you for your comment. That part I mentioned was among the defauls of the code that could not be changed. So the problem was solved. Thanks again for your help.
Zayad
Zayad on 12 Dec 2023
how did you solve it?

Sign in to comment.

Answers (2)

Ganesh Regoti
Ganesh Regoti on 28 Apr 2020
Hi Vahid,
By the error statement, I would say it might be a syntactical error. Go through the code to check if it is properly formatted and ended. Regarding the solid statements,
  1. When you create an app from app designer, there is a default code generated based on the components which is non-editable.
  2. When you add callbacks, properties, methods, an editable area is created with declarations where you can edit/add your code.
Here are the links you refer to for more information
Hope this helps!
  1 Comment
Vahid Abolhasannejad
Vahid Abolhasannejad on 7 Apr 2021
Hello Ganesh, thank you for your comment. That part I mentioned was among the defauls of the code that could not be changed. So the problem was solved. Thanks again for your help.

Sign in to comment.


Justi Kertusha
Justi Kertusha on 30 Nov 2023
Edited: Walter Roberson on 3 Dec 2023
% LightBehaviorApp.m
classdef LightBehaviorApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access=public)
UIFigure matlab.ui.Figure
Material1EditField matlab.ui.control.NumericEditField
Material2EditField matlab.ui.control.NumericEditField
IncidentAngleEditField matlab.ui.control.NumericEditField
CalculateButton matlab.ui.control.Button
TrajectoryAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods(Access=private)
% Code that executes after component creation
function startupFcn(app)
% Set default values for the indices of refraction
app.Material1EditField.Value = 1.5;
app.Material2EditField.Value = 1.0;
app.IncidentAngleEditField.Value = 45;
end
% Button pushed function
function CalculateButtonPushed(app, ~)
% Get user inputs
n1 = app.Material1EditField.Value;
n2 = app.Material2EditField.Value;
incidentAngle = app.IncidentAngleEditField.Value;
% Calculate refraction angle using Snell's Law
refractedAngle = asind((n1/n2) * sind(incidentAngle));
% Plot the trajectory of light within each medium
cla(app.TrajectoryAxes);
hold(app.TrajectoryAxes, 'on');
plot(app.TrajectoryAxes, [0, cosd(incidentAngle)], [0, sind(incidentAngle)]);
plot(app.TrajectoryAxes, [0, cosd(refractedAngle)], [-sind(incidentAngle), -sind(incidentAngle)]);
hold(app.TrajectoryAxes, 'off');
axis(app.TrajectoryAxes, 'equal');
title(app.TrajectoryAxes, 'Light Trajectory');
legend(app.TrajectoryAxes, {'Incident Ray', 'Refracted Ray'});
end
end
% App creation and deletion
methods (Access=public)
% Construct app
function app = LightBehaviorApp
% 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
% Function to create and configure UI components
methods (Access=private)
function createComponents(app)
% Create UIFigure and set its properties
app.UIFigure = matlab.ui.Figure('Visible', 'off');
app.UIFigure.Position = [100, 100, 600, 400];
app.UIFigure.Name = 'LightBehaviorApp';
% Create Material1EditField component
app.Material1EditField = matlab.ui.control.NumericEditField(app.UIFigure);
app.Material1EditField.Position = [100, 300, 100, 30];
app.Material1EditField.String = '1.5';
app.Material1EditField.Label = 'Material 1 Refractive Index';
% Create Material2EditField component
app.Material2EditField = matlab.ui.control.NumericEditField(app.UIFigure);
app.Material2EditField.Position = [100, 250, 100, 30];
app.Material2EditField.String = '1.0';
app.Material2EditField.Label = 'Material 2 Refractive Index';
% Create IncidentAngleEditField component
app.IncidentAngleEditField = matlab.ui.control.NumericEditField(app.UIFigure);
app.IncidentAngleEditField.Position = [100, 200, 100, 30];
app.IncidentAngleEditField.String = '45';
app.IncidentAngleEditField.Label = 'Incident Angle';
% Create CalculateButton component
app.CalculateButton = matlab.ui.control.Button(app.UIFigure);
app.CalculateButton.Position = [250, 200, 100, 30];
app.CalculateButton.Text = 'Calculate';
app.CalculateButton.ButtonPushedFcn = @app.CalculateButtonPushed;
% Create TrajectoryAxes component
app.TrajectoryAxes = matlab.ui.control.UIAxes(app.UIFigure);
app.TrajectoryAxes.Position = [400, 100, 150, 200];
end
end
end
This is given me an error in line 55
Error in LightBehaviorApp (line 55)
createComponents(app);
  1 Comment
Walter Roberson
Walter Roberson on 3 Dec 2023
app.Material1EditField = matlab.ui.control.NumericEditField(app.UIFigure);
When you call matlab.ui.control.NumericEditField directly, then any parameters you pass must be paired, property/value form. When you call it directly, it does not accept a figure positionally.
You should be calling uieditfield(app.UIFigure,"numeric") instead.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!