App designer: Unbalanced or unexpected parenthesis or bracket
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
David Sanchez Manzano
am 4 Dez. 2017
Kommentiert: David Sanchez Manzano
am 6 Dez. 2017
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 Kommentare
Stephen23
am 4 Dez. 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.
Akzeptierte Antwort
Elizabeth Reese
am 6 Dez. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!