App designer: Unbalanced or unexpected parenthesis or bracket
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David Sanchez Manzano
el 4 de Dic. de 2017
Comentada: David Sanchez Manzano
el 6 de Dic. de 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 comentarios
Stephen23
el 4 de Dic. de 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.
Respuesta aceptada
Elizabeth Reese
el 6 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!