App designer: Unbalanced or unexpected parenthesis or bracket
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2017-12-4
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.
采纳的回答
Elizabeth Reese
2017-12-6
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!