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

조회 수: 10 (최근 30일)
Alon Rozen
Alon Rozen 2020년 2월 12일
댓글: Alon Rozen 2020년 2월 12일
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

채택된 답변

dpb
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.

추가 답변 (1개)

Alon Rozen
Alon Rozen 2020년 2월 12일
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.
Alon
  댓글 수: 2
dpb
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.
Alon Rozen
Alon Rozen 2020년 2월 12일
Thanks again!
This is cool. Going to do just that.
Alon

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by