Asking user is they want to save matrix to text file.
6 次查看(过去 30 天)
显示 更早的评论
I have a program that generates a matrix based on user inputs called T and I'm trying to ask the user if they would like to save this matrix to a text file. If they do I want the file name to be specified by the user. If they don't want to save it, the program can just end. Here is what I have so far:
text = menu('Would you like to save data to a text file?','Yes','No');
if text == 1
1 个评论
Walter Roberson
2018-4-15
That looks okay so far, except I would recommend using a different variable name so you do not interfere with using the text() function
回答(1 个)
dpb
2018-4-15
编辑:dpb
2018-4-15
While the above will work, menu has been deprecated; perhaps use questdlg instead...
option=questdlg('Save to text file?', ...
'Save File',...
'Yes', 'No','Yes');
% Handle response
switch option
case 'Yes'
fn=uiputfile(... % call the savefile dialog if 'yes'
case 'No'
return % nothing left to do, maybe...
end
Altho I'm a more "get me to the point" kinda' guy and for my own use I'd just go ahead and call uiputfile straighaway; the user can always cancel. Of course, if is a less-experienced user, perhaps the extra step of coaching is better; that's purely personal choice...
10 个评论
Walter Roberson
2018-4-15
So? questdlg() can be closed by clicking on the x ?
^C should interrupt anything. It should interrupt questdlg too. And indeed in my test if you focus on the command window, control-C, click to focus on the command window again, and control-C again, then
Operation terminated by user during uiwait (line 81)
In questdlg (line 428)
uiwait(QuestFig);
For the point about ^C to have any relevance, questdlg would have to prevent that too.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!