How can I get information that a 'uisave' command was aborted?
5 次查看(过去 30 天)
显示 更早的评论
Hi,
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'?
Thanks,
Alon
0 个评论
采纳的回答
dpb
2020-2-12
编辑:dpb
2020-2-12
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.
ADDENDUM:
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)
to
function [fn,pn,filterindex]=uisave(variables, filename)
which would give the same return values as one gets from uiputfile.
0 个评论
更多回答(1 个)
Alon Rozen
2020-2-12
2 个评论
dpb
2020-2-12
编辑:dpb
2020-2-12
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.
另请参阅
类别
在 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!