App designer: Unbalanced or unexpected parenthesis or bracket

4 views (last 30 days)
Hi everyone,
I'm trying to learn how to use the AppDesigner.
In my app, i'm using the uigetfile command in a public property to obtain the filenames and path of multiple files. But it always gives me the "Unbalanced or unexpected parenthesis or bracket", even when it doesn't appear when I use the exact same command in the command window. This is it:
[filename,pathname]=uigetfile('*.mat','MAT-files (*.mat)', 'MultiSelect', 'on');
If I only put filename=uigetfile... it works. But I need the filename and the pathname.
Anyone knows why this happens?
Thank you!
  2 Comments
Stephen23
Stephen23 on 4 Dec 2017
The unbalanced bracket or parenthesis might be on a preceding or trailing line. Please upload the code for use to see. Make a new comment and click the paperclip button.
Also please give the entire error message. This means all of the red text.
David Sanchez Manzano
David Sanchez Manzano on 4 Dec 2017
I attach the code, it's just the code of the app designer + the line I wrote before. The entire error message is :
Error using PruebaFMR Error: File: PruebaFMR.mlapp Line: 16 Column: 9 Unbalanced or unexpected parenthesis or bracket.

Sign in to comment.

Accepted Answer

Elizabeth Reese
Elizabeth Reese on 6 Dec 2017
This is happening because of the "[" that is at the beginning of the line. In MATLAB classes (how App Designer applications are represented) you cannot define properties in this way. This page explains more about how MATLAB classes use properties. If you want the filename and pathname to be properties of your application, then you can declare them in the Properties block and then define them later on with the uigetfile.
For example:
properties (Access = private)
filename
pathname
end
Then, in add the "StartupFcn" callback to your figure. You can do this by right-clicking the figure in the Design View and selecting Callbacks > add StartupFcn Callback or in the Code View by pressing in the "Callbacks" tab of the Code Browser.
In the StartupFcn, you can add the code for the uigetfile and save the file name and path to the app's properties.
function startupFcn(app)
% app.UIFigure.Visible = 'off';
[app.filename,app.pathname]=uigetfile('*.mat','MAT-files (*.mat)', 'MultiSelect', 'on');
% app.UIFigure.Visible = 'on';
end
The two commented out lines change the visibility of the figure, so you can uncomment them if you want the file selector to open before the rest of your application and then, once the user selects the file, the app will show up. If they are commented out, then both windows will open and you cannot guarantee that the user of your app selects or cancels from the file selector before the rest of the app is used.

More Answers (0)

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!