필터 지우기
필터 지우기

I need to generate a GUI that displays a random number between 0-10000 everytime "Button" is pressed

조회 수: 3 (최근 30일)
- I am really not sure how to go about this and any help would be great. I have the GUI set up, but not sure what type of text box to use or how to set it to display

채택된 답변

Jan
Jan 2017년 7월 7일
편집: Jan 2017년 7월 7일
function YourGUI
FigH = figure('Name', 'Your GUI', ...
'IntegerHandle', 'off', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Resize', 'off', ...
'Units', 'pixels', ...
'Position', [200, 200, 300, 120], ...
'NextPlot', 'add');
DispH = uicontrol('Style', 'edit', 'String', '', ...
'Enable', 'inactive', ... % Cannot be edited
'Position', [10, 60, 280, 50], ...
'FontSize', 24, 'HorizontalAlignment', 'Center');
ButtonH = uicontrol('Style', 'PushButton', 'String', 'Click on me', ...
'Position', [50, 10, 200, 30], ...
'FontSize', 16, ...
'Callback', {@ButtonCB, DispH});
end
function ButtonCB(BunttonH, EventData, DispH)
Num = randi([0, 10000]); % Integer
% Or: Num = rand * 10000; % Floating point
set(DispH, 'String', sprintf('%g', Num));
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 7월 7일
Create a uicontrol('style', 'text') with appropriate 'Units' and 'Position' setting. Record its handle somewhere. Then each time the button is pressed, create a random number in the appropriate range and set the String property of the uicontrol to the number.

카테고리

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