Asking user is they want to save matrix to text file.
2 ビュー (過去 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!