Error in app designer

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

The first thing I would look for is whether the classdef line is missing or commented out, or there is code before the classdef line.
Thank you Walter for your message,
I have my own code above this statement. I have actually designed an application. Here is some lines above and more lines bellow this statement:
% Button pushed function: VisualizeOriginalChannelButton
function VisualizeOriginalChannelButtonPushed(app, event)
end
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 1316 959];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'ECG Diagram')
xlabel(app.UIAxes, 'Time')
ylabel(app.UIAxes, 'Voltage')
app.UIAxes.Position = [71 474 927 447];
% Create VisualizationPannelPanel
app.VisualizationPannelPanel = uipanel(app.UIFigure);
app.VisualizationPannelPanel.Title = 'Visualization Pannel';
app.VisualizationPannelPanel.Position = [111 202 210 221];
% Create CannelNoDropDownLabel
app.CannelNoDropDownLabel = uilabel(app.VisualizationPannelPanel);
app.CannelNoDropDownLabel.HorizontalAlignment = 'right';
app.CannelNoDropDownLabel.Position = [12 156 66 22];
app.CannelNoDropDownLabel.Text = 'Cannel No.';
% Create CannelNoDropDown
app.CannelNoDropDown = uidropdown(app.VisualizationPannelPanel);
app.CannelNoDropDown.Items = {'Chennel 1', 'Channel 2'};
app.CannelNoDropDown.Position = [93 156 100 22];
app.CannelNoDropDown.Value = 'Chennel 1';
% Create VisualizeOriginalChannelButton
app.VisualizeOriginalChannelButton = uibutton(app.VisualizationPannelPanel, 'push');
app.VisualizeOriginalChannelButton.ButtonPushedFcn = createCallbackFcn(app, @VisualizeOriginalChannelButtonPushed, true);
app.VisualizeOriginalChannelButton.Position = [29 110 156 22];
app.VisualizeOriginalChannelButton.Text = 'Visualize Original Channel';
% Create VisualizeCleanChannelButton
app.VisualizeCleanChannelButton = uibutton(app.VisualizationPannelPanel, 'push');
app.VisualizeCleanChannelButton.Position = [29 70 156 22];
app.VisualizeCleanChannelButton.Text = 'Visualize Clean Channel';
% Create ClearPlotButton
app.ClearPlotButton = uibutton(app.VisualizationPannelPanel, 'push');
app.ClearPlotButton.Position = [29 31 156 22];
app.ClearPlotButton.Text = 'Clear Plot';
% Create Panel
app.Panel = uipanel(app.UIFigure);
app.Panel.Title = 'Panel';
app.Panel.Position = [538 201 452 221];
% Create ChannelNoDropDownLabel
app.ChannelNoDropDownLabel = uilabel(app.Panel);
app.ChannelNoDropDownLabel.HorizontalAlignment = 'right';
app.ChannelNoDropDownLabel.Position = [15 156 72 22];
app.ChannelNoDropDownLabel.Text = 'Channel No.';
% Create ChannelNoDropDown
app.ChannelNoDropDown = uidropdown(app.Panel);
app.ChannelNoDropDown.Items = {'Channel 1', 'Channel 2', ''};
app.ChannelNoDropDown.Position = [102 156 100 22];
app.ChannelNoDropDown.Value = 'Channel 1';
% Create FromTimeEditFieldLabel
app.FromTimeEditFieldLabel = uilabel(app.Panel);
app.FromTimeEditFieldLabel.HorizontalAlignment = 'right';
app.FromTimeEditFieldLabel.Position = [24 115 63 22];
app.FromTimeEditFieldLabel.Text = 'From Time';
% Create FromTimeEditField
app.FromTimeEditField = uieditfield(app.Panel, 'numeric');
app.FromTimeEditField.Position = [102 115 100 22];
% Create ToTimeEditFieldLabel
app.ToTimeEditFieldLabel = uilabel(app.Panel);
app.ToTimeEditFieldLabel.HorizontalAlignment = 'right';
app.ToTimeEditFieldLabel.Position = [40 70 48 22];
app.ToTimeEditFieldLabel.Text = 'To Time';
% Create ToTimeEditField
app.ToTimeEditField = uieditfield(app.Panel, 'numeric');
app.ToTimeEditField.Position = [103 70 99 22];
% Create FromTimeEditField_2Label
app.FromTimeEditField_2Label = uilabel(app.Panel);
app.FromTimeEditField_2Label.HorizontalAlignment = 'right';
app.FromTimeEditField_2Label.Position = [232 115 63 22];
app.FromTimeEditField_2Label.Text = 'From Time';
% Create FromTimeEditField_2
app.FromTimeEditField_2 = uieditfield(app.Panel, 'numeric');
app.FromTimeEditField_2.Position = [310 115 100 22];
% Create ToTimeEditField_2Label
app.ToTimeEditField_2Label = uilabel(app.Panel);
app.ToTimeEditField_2Label.HorizontalAlignment = 'right';
app.ToTimeEditField_2Label.Position = [247 70 48 22];
app.ToTimeEditField_2Label.Text = 'To Time';
% Create ToTimeEditField_2
app.ToTimeEditField_2 = uieditfield(app.Panel, 'numeric');
app.ToTimeEditField_2.Position = [310 70 100 22];
% Create CompareECGButton
app.CompareECGButton = uibutton(app.Panel, 'push');
app.CompareECGButton.Position = [35 20 179 22];
app.CompareECGButton.Text = 'Compare ECG ';
% Create ClearPlotButton_2
app.ClearPlotButton_2 = uibutton(app.Panel, 'push');
app.ClearPlotButton_2.Position = [279 20 100 22];
app.ClearPlotButton_2.Text = 'Clear Plot';
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'Clean Time Periods'};
app.UITable.RowName = {};
app.UITable.Position = [358 202 139 221];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
methods is only permitted inside a classdef . For example it might start
classdef PPPH < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
Your line with function VisualizeOriginalChannelButtonPushed should have appeared much further down in the file, in a methods section.
Did you accidently used additional "end" keywords in the editable portion of your code ?
% Button pushed function: VisualizeOriginalChannelButton
function VisualizeOriginalChannelButtonPushed(app, event)
end
end
end
I just coppied some parts of the code. Those "end" statements correspond with the above code parts.
We need the actual code to examine, not just a subset of it, as the parts you are cutting out might be the parts the problem is occuring in.
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

0 votes

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

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

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

Asked:

on 20 Apr 2020

Commented:

on 12 Dec 2023

Community Treasure Hunt

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

Start Hunting!