uiputfile blocks all of MatLab any error it keeps repeating, it requires CTR-ALT-DEL end task (my app) to exit
Show older comments
I wrote this code that ends up being an endless loop Due to weird treatment of this particular dialog
I can't add a breakpoint while (Save to) is open looking for a path from the call uiputfile(...
Code that I think should run fine is in an endless loop that can't be exited since all of MatLab all is locked out.
Even after CTR-ALT-DEL End task the dialog stays open, but at least with no calling app I can finally close it.
No Ctrl-C allowed anywhere, No response from Command Window, App Designer or my app itself, just endless beeps and reopening the dialog. Neither OK or cancel gets out of it but in the example below Cancel with throw an erro so you won't have my problem
Try this (modified code, removing app.propertied to work in your command window
The goal is to exit the while with a valid path (app.)OutLoc
startingFolder = "";
baseFileName = '*.csv';
OutLoc = ""; % Must use "" as isfolder thinks " " is a folder!
while ~isfolder(OutLoc) % Let's stay here until it's good
defaultFileName = fullfile(startingFolder,baseFileName);
% Show all files in the folder by using "*.*"
[baseFileName, startingFolder] = uiputfile('*.*', ...
'Save to', defaultFileName);
% Various ways of chacking throw wrong type errors so I settled on this
if size(baseFileName,2)<6 % Is baseFileName any good (or even a string)?
% User clicked the Cancel button. or didn't enter a file
uialert(app.MouseOdor,"No file name given","No Output File"); % Crash when not running it app
end
if ~isstring(startingFolder) % because uiputfile() will change it to 0 on cancel
startingFolder = "";
end
if isfolder(startingFolder)
OutLoc = startingFolder; % All good, should exit the loop now
MouseFolder = startingFolder; % actually saving it to app.MouseFolder.Value for later use
end
end % while
I tried running it in here, so now I know it's a Java issue... lovely.
I guess you will have to copy and paste it to your command window and try yourself.
BTW, I'm in 2023b, probably time to upgrade
Also, when I ask a question like the above does Ask the Community page not allow any text into the Description* block.
How does it decide it doesn't like my question?
6 Comments
Walter Roberson
on 18 Sep 2024
Doesn't fill in startingFolder it's still empty if I give a file name with no extension.
I am not able to replicate that behaviour with R2024b for MacOS Intel
"...the goal is to exit the while with a valid path (app.)OutLoc"
%...
%OutLoc = ""; % Must use "" as isfolder thinks " " is a folder!
%while ~isfolder(OutLoc) % Let's stay here until it's good
%...
I hadn't ever tried that, but I would submit that
isfolder(' ')
returning True is a bug and should be reported as such unless on Linux and there actually is a folder with " " as its name (allowable, but not necessarily wise). Converting it back to the empty string will be the cause of the infinite loop.
The comment above about "~isstring() was a first thought I had -- the doc says the output path is a char() vector while the filename can be either a string or a char() vector (what cause which isn't described; that's a deficiency in the doc) but I'd suggest using
while ~(exist(OutLoc)==7)
as more robust given the above behavior of isfolder()
Swastik Sarkar
on 23 Sep 2024
Doesn't fill in startingFolder it's still empty if I give a file name with no extension.
I've tested this on MATLAB R2023b on both Windows and Debian 12 (Linux), but I haven't been able to reproduce the problem.
It would be helpful to have the code for the app to determine if the issue can be replicated.
input = " ";
input = fl::filesystem::absolute(input)
The example in the linked-to Answer doesn't work under R2021b.
I suppose one can make the argument they do that
isfolder(fn)
is evaluated as
isfolder(trim(fn))
but it's still imo unexpected behavior in MATLAB since a blank folder can't exist under Windows...
No way one will change TMW's mind on this one, however, so best one could do would be to ask for a note to be added to the documentation regarding that behavior. And, of course, it is true for all related functions, not just isfolder
Accepted Answer
More Answers (0)
Categories
Find more on Whos 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!