why msgbox for input make the code no response
古いコメントを表示
hi,
whhy when create msgbox for input value within code , the window of input is not responding. But I used it in other function , it is work.
thanks
回答 (2 件)
Image Analyst
2014 年 3 月 2 日
0 投票
msgbox's only input is a string that it displays to the user. It does not accept input from the user, only from the programmer. If you want to accept input from the user, use questdlg() or inputdlg().
4 件のコメント
nada ali
2014 年 3 月 2 日
nada ali
2014 年 3 月 2 日
Image Analyst
2014 年 3 月 2 日
Try this code:
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
nada ali
2014 年 3 月 2 日
Image Analyst
2014 年 3 月 2 日
0 投票
Not sure what that means and I didn't run the code. But if you want a response from a message box presented to the user, you're going to have to use questdlg() instead of msgbox().
2 件のコメント
nada ali
2014 年 3 月 3 日
Image Analyst
2014 年 3 月 3 日
You can either use inputdlg(), input(), or write your own GUI.
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!