MATLAB Answers

How can I get information that a 'uisave' command was aborted?

3 views (last 30 days)
Alon Rozen
Alon Rozen on 12 Feb 2020
Commented: Alon Rozen on 12 Feb 2020
I want to save certain variables in a mat file using specific name in a chosen directory.
For that I use 'uisave'. I could use uiputfile but I need only few variables out of many in the work space.
After this is done I want to write a message: 'Save finished successfully'.
In the case where the user aborted the save dialog box I want to konw it so I can write 'Save was aborted by user'.
How can I get the information that the user pushd 'Cancel' istead of 'Save'?


Sign in to comment.

Accepted Answer

dpb on 12 Feb 2020
Edited: dpb on 12 Feb 2020
No can do. Less than primo "Quality of Implemenation" that TMW didn't have an optional return value from uisave
>> fn=uisave('R','Temp')
Error using uisave
Too many output arguments.
Worth an enhancement request/bug report.
It is an m-file, and is a wrapper around a call to uiputfile however, so one could make a local version of your own that does return the file variable to test for 0 as does uiputfile or modify it to return a flag/logical variable. The dual use of the file name as the logical is also a marginal design by current thinking but was prevalent in the time the original was written. Hence is probably best choice for consistency in keeping with existing functions.
The user can modify the filename in the uisave dialog, so that is another reason it would be best choice to return the filename so can also know if the user changed the default name.
Never used so had to go look at what it actually does. All would take would be to change the existing function definition line from
function uisave(variables, filename)
function [fn,pn,filterindex]=uisave(variables, filename)
which would give the same return values as one gets from uiputfile.


Sign in to comment.

More Answers (1)

Alon Rozen
Alon Rozen on 12 Feb 2020
Thanks dpb,
I will try to play with your idea.
My main concern is that other use my uitility so I can't change this function on their computers.


dpb on 12 Feb 2020
Don't change the TMW-supplied function, create a copy of it in a place on your user working path and make the modifications therein. Also rename it to something slightly different so it doesn't alias the builtin function as well.
Then, you supply this new function as part of your application just like any of the other functions you've built.
One way to package it would be to include it in the m-file that uses it--then it is private to that file alone (presuming the call in your app is localized to one location). If that isn't so, then you can always create a private subdirectory for it to go along with your distributed file(s). Or leave it public but give it a unique name just as if you were to "roll your own" from scratch not knowing TMW had supplied uisave at all.
I didn't bother to make the change above but as noted here and there, don't use the name uisave but
function [fn,pn,filterindex]=my_uisave(variables, filename)
or some other way to make it unique.
Alon Rozen
Alon Rozen on 12 Feb 2020
Thanks again!
This is cool. Going to do just that.

Sign in to comment.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!