Need help extracting the input from a dialog box and then fprintf it in the command window.
7 ビュー (過去 30 日間)
古いコメントを表示
I am trying to create a dialog box that asks two players for their names. I have the dialog box working fine I just need help in extracting the string that the user inputs and using fprintf to display it in the command window.
This is what I have so far, I have tried using str2num and other things I just keep getting error messages.
Here is my code:
Prompts = {'What is the name of Player 1?', 'What is the name of Player2?'}; DialogBox = inputdlg(Prompts);
Player1Name = x(1); Player2Name = x(2);
fprintf('%s = Player1', Player1Name) fprintf('%s = Player2', Player2Name)
Thank you all so much!
0 件のコメント
採用された回答
Image Analyst
2013 年 4 月 14 日
Try this:
Prompts = {'What is the name of Player 1?', 'What is the name of Player2?'};
titleBar = 'Enter data';
caUserInput = inputdlg(Prompts, titleBar, 2);
if isempty(caUserInput)
return
end; % Bail out if they clicked Cancel.
Player1Name = char(caUserInput(1));
Player2Name = char(caUserInput(2));
fprintf('%s = Player1\n%s = Player2\n',...
Player1Name, Player2Name)
0 件のコメント
その他の回答 (1 件)
Cedric
2013 年 4 月 14 日
編集済み: Cedric
2013 年 4 月 14 日
Almost correct; just bring the following change:
fprintf( '%s = Player1\n', DialogBox{1} ) ;
fprintf( '%s = Player2\n', DialogBox{2} ) ;
INPUTDLG returns a cell array (that you named DialogBox). Its cells contain user inputs. Note the curly brackets for indexing DialogBox, as you want to extract cell's content.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!