How do i get user input into msgbox

조회 수: 7 (최근 30일)
Joseph Kain
Joseph Kain 2016년 2월 29일
댓글: Joseph Kain 2016년 2월 29일
So for my engineering project, I am creating a text based adventure because it sounds fun. So the first prompt players are greeted with is as follows:
playername = inputdlg('Welcome to The RPG, what is your name?:', 'RPG', 1);
charactername= playername{1};
msgbox(sprintf('Nice to meet you %g', charactername))
So the player is suppose to enter their name, and then I'd like the message box to restate their name, but when I run the code this happens "Nice to meet you98Nice to meet you 101Nice to meet you 110"
Any ideas?
  댓글 수: 1
Joseph Kain
Joseph Kain 2016년 2월 29일
I got it it, heres the code:
playername = inputdlg('Welcome to The RPG, what is your name?:', ' RPG', 1);
charactername= char(playername(1));
msgbox(sprintf('Nice to meet you %s\n', charactername))

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 29일
%s not %g

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by