필터 지우기
필터 지우기

I need help writing a script for an edit box

조회 수: 2 (최근 30일)
Amanda
Amanda 2022년 11월 14일
댓글: Rik 2022년 11월 15일
I need help writing a script for and edit box and button. When the button is pressed I need my robot to walk forward as many steps specified in the edit box. I need to write a call back function for the button where it reads the edit box and then calls walk from the robot inter face to go that many steps.
createRandomMaze
figure;
first_button = uicontrol('style', 'pushbutton');
set(first_button, 'units', 'normalized', 'position', [0.2,0.7, 0.2, 0.2])
set(first_button, 'string', 'turn left')
set(first_button, 'callback', @turnLeft)
second_button = uicontrol('style', 'pushbutton');
set(second_button, 'units', 'normalized', 'position', [0.4, 0.7, 0.2, 0.2])
set(second_button, 'string', 'step')
set(second_button, 'callback', @step)
third_button = uicontrol('style', 'pushbutton');
set(third_button, 'units', 'normalized', 'position', [0.6, 0.7, 0.2, 0.2])
set(third_button, 'string', 'turn right')
set(third_button, 'callback', @turnRight)
fourth_button = uicontrol('style', 'pushbutton');
set(fourth_button, 'units', 'normalized', 'position', [0.2, 0.5, 0.2, 0.2])
set(fourth_button, 'string', 'left')
set(fourth_button, 'callback', @turnLeft)
fifth_button = uicontrol('style', 'pushbutton');
set(fifth_button, 'units', 'normalized', 'position', [0.4, 0.5, 0.2, 0.2])
set(fifth_button, 'string', 'back')
set(fifth_button, 'callback', @step)
sixth_button = uicontrol('style', 'pushbutton');
set(sixth_button, 'units', 'normalized', 'position', [0.6, 0.5, 0.2, 0.2])
set(sixth_button, 'string', 'right')
seventh_button = uicontrol ('style','checkbox');
set(seventh_button, 'units', 'normalized', 'position', [0.2, 0.3, 0.2, 0.2])
set(seventh_button, 'string', 'History')
set(seventh_button, 'callback', @toggleHistory)
eighth_button = uicontrol ('style', 'edit');
set(eighth_button, 'units', 'normalized', 'position', [0.4, 0.37, 0.2, 0.05])
set(eighth_button, 'string', '2')
ninth_button = uicontrol('style','pushbutton');
set(ninth_button, 'units', 'normalized', 'position', [0.6, 0.3, 0.2, 0.2])
set(ninth_button, 'string', 'Run!')
function toggleHistory(sender, evendata)
if sender.Value == 1
disp showHistory
else
disp hideHistory
end
end
This is what I have created so far
  댓글 수: 1
Rik
Rik 2022년 11월 15일
Why are you numbering your buttons instead of giving them names? And why are you not storing the handles in a struct in the guidata?
For general advice and examples for how to create a GUI, have look at this thread. It seems you are doing some of the right things already, but you need to make a cohesive whole. You should also remember to always use explicit parents when creating or modifying graphics object when dealing with a GUI.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by