uigetfile in appdesigner freezes MATLAB
10 次查看(过去 30 天)
显示 更早的评论
In a button click function , I have the following lines of code
file=uigetfile;
app.fileToImport =file;
drawnow;pause(0.05);
The uigetfile somehow pauses the shell. I saw the following error:
Operation terminated by user during matlab.ui.internal.dialog.FileChooser/blockMATLAB (line 390)
In matlab.ui.internal.dialog.FileChooser/showPeerAndBlockMATLAB (line 115)
blockMATLAB(obj);
In matlab.ui.internal.dialog.FileChooser/show (line 122)
obj.showPeerAndBlockMATLAB();
In uigetputfile_helper (line 56)
ufd.show();
In uigetfile (line 130)
[filename, pathname, filterindex] = uigetputfile_helper(0, varargin{:});
In gui2/ImportDataButtonPushed (line 279)
file=uigetfile;
In appdesigner.internal.service.AppManagementService/tryCallback (line 362)
callback(app, event);
In matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event)
(line 37)
newCallback = @(source, event)tryCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Interrupt while evaluating Button PrivateButtonPushedFcn.
I added the drawnow and pause because I saw that solution somewhere but it does not seem to work. uigetfile worked everytime when I used it out of appdesigner but now it somehow causes the error everytime. I can resume the program somehow and it still works but I do not understand why it is freezing the operation.
I also found the following line
com.mathworks.mwswing.MJFileChooserPerPlatform.setUseSwingDialog(1)
But matlab does not suggest using it. What could be the reason for this and how can it be resolved?
7 个评论
dpb
2022-6-15
编辑:dpb
2022-6-16
In the code you posted the app.data variable was never being set so you weren't in synch with having data with the button callback...now it is it's there, but I'd not use importdata for this because it can return different formats of the data depending upon the file without notification -- and I'd also strongly recommend to use a fully-qualified file name. I don't know that either of those would trigger the symptoms you're seeing, but they're weak points in the existing code.
We can only see what you post; if that doesn't match the exact code in the app then it's easy (almost guaranteed?) to draw incorrect inferences.
I'd suggest building an independent app with just the uigetfile call and reading the file and then see if the symptom follows -- or if it is only tied into the specific app that indicates there's something elsewhere funky in it. If the symptom is repeated, that would imply something in the OS/Java/the MATLAB install itself.
回答(2 个)
Benjamin Thompson
2022-6-13
uigetfile is supposed to open a file selection dialog box and let the user select a file? Do you not see that dialog box pop up? It is supposed to pause execution to wait for this input from the user.
Co Melissant
2023-4-17
编辑:Co Melissant
2023-4-17
Running 20b the workaround as mentioned in https://nl.mathworks.com/matlabcentral/answers/361755-matlab-freeze-when-using-a-file-dialog-selection works for me!
just add:
com.mathworks.mwswing.MJFileChooserPerPlatform.setUseSwingDialog(1)
The infamous other solution, that also worked for me, and proposed by Yair https://undocumentedmatlab.com/articles/solving-a-matlab-hang-problem
drawnow;
pause(0.5);
drawnow;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!