필터 지우기
필터 지우기

숫자야구 gui 만들고 싶습니다 ㅠㅠ

조회 수: 3 (최근 30일)
동진 정
동진 정 2021년 11월 24일
답변: Saurabh 2024년 2월 26일
num1 = randi(10) - 1; % 0부터 9사이의 랜덤정수 설정
num2 = num1;
while num2==num1
num2= randi(10)-1;
end
num3=num2;
while num3 == num2 || num3 == num1
num3=randi(10)-1;
end
num=[num1,num2,num3];
s_cnt=0;
challenge_num=0;
while s_cnt~=3
challenge_num=challenge_num+1;
disp(['<Round', num2str(challenge_num), '>'])
s_cnt=0;
b_cnt=0;
prompt1='num1:';
x1=input(prompt1);
prompt2='num2:';
x2=input(prompt2);
prompt3='num3:';
x3=input(prompt3);
if x1==num1
s_cnt=s_cnt+1;
end
if x2==num2
s_cnt=s_cnt+1;
end
if x3==num3
s_cnt=s_cnt+1;
end
if x1==num2 || x1==num3
b_cnt=b_cnt+1;
end
if x2 == num1 || x2==num3
b_cnt=b_cnt+1;
end
if x3 ==num1 || x3 == num2
b_cnt = b_cnt+1;
end
result=[num2str(s_cnt),'S',num2str(b_cnt),'B.'];
disp(result)
disp(' ')
end
disp('The end')
disp(['The number of challenges:',num2str(challenge_num)])
위에는 숫자야구를 실행하는 코드 입니다. 저는 이 코드를 GUI에서 구현 시키고 싶은데 체크박스라던지 텍스트 상자, 푸시버튼을 만들어도 어디에 어느 코드를 넣어야하는지 전혀 모르겠습니다 ㅠㅠ 도움좀 주실수 있으신가요... 부탁드립니다.
  댓글 수: 1
Kyoung Moon Lee
Kyoung Moon Lee 2023년 9월 12일
편집: Kyoung Moon Lee 2023년 9월 12일
해당 링크를 통해 메뉴얼과 스크립트에서 사용가능한 리스트를 볼 수 있습니다.

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

답변 (1개)

Saurabh
Saurabh 2024년 2월 26일
Hi 동진 정,
It appears that you want to improve your baseball game by adding UI elements to make the experience more exciting.
You may incorporate a GUI window into your game in a few different ways.
I will go over the two main strategies; you can choose the one that best fits the objectives of your project.
  • In the first approach, the GUI window is created using the ‘uifigure’ function, after which UI elements like text boxes and push buttons can be added. This solution requires manual coding of the UI elements and their behaviors and an in-depth knowledge of MATLAB's graphics system.
  • Alternatively, APP Designerprovides a more approachable option for individuals who are unfamiliar with GUI programming. It offers a modern drag-and-drop app development interface that simplifies the GUI construction process, easy to implement function, positioning of UI Components is easy.
Below is an example of how you might set up the callback function for the submit button in App Designer, which I tried on my end:
num1 = randi(10) - 1; % 0부터 9사이의 랜덤정수 설정
num2 = num1;
while num2==num1
num2= randi(10)-1;
end
num3=num2;
while num3 == num2 || num3 == num1
num3=randi(10)-1;
end
num=[num1,num2,num3];
% disp(num)
x1 = str2double(app.num1EditField.Value);
x2 = str2double(app.num2EditField.Value);
x3 = str2double(app.num3EditField.Value);
s_cnt=0;
challenge_num=0;
% continue with the required logic.
To learn more about the ‘APP Designer’ and uifigurefunction, you may refer to the MathWorks documentation links below:
I hope this was helpful.

카테고리

Help CenterFile Exchange에서 GUIDE 앱 마이그레이션하기에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!