필터 지우기
필터 지우기

Controlling GUI through a matlab code

조회 수: 2 (최근 30일)
Hend Faiad
Hend Faiad 2022년 6월 4일
답변: Tom Teasdale 2022년 6월 10일
  • How can I write a matlab code that controls the appearacne of textboxes and button in a GUI?
  • for instance I want matlab to display n textboxes when I input n to a text box in GUI,How can I do that?
  댓글 수: 2
Benjamin Thompson
Benjamin Thompson 2022년 6월 4일
Try looking over the article titled "App Building" in the documentation and see what approach best meets your requirements. Then ask the Community more questions with some sample code of the work you have done or more details about how you would like it to work.
Walter Roberson
Walter Roberson 2022년 6월 4일
generally speaking if you have a fixed maximum number of them it can sometimes be easier to create them all at design time but make them invisible until needed.

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

답변 (1개)

Tom Teasdale
Tom Teasdale 2022년 6월 10일
Hello,
I understand you want to programatically create a varying number of UI components. Your second question could be implemented as follows. Paste this example into a Live Script to execute it yourself.
gridMain = uigridlayout(...
'RowHeight', {'fit', '1x'}, ...
'ColumnWidth', {'1x', 'fit'});
gridTextAreas = uigridlayout(gridMain, ...
'ColumnWidth', {'1x'}, ...
'Scrollable', 'on');
gridTextAreas.Layout.Row = [1 numel(gridMain.RowHeight)];
editfield = uieditfield(gridMain, 'numeric', ...
'ValueChangedFcn', @(~,e) onValueChanged(gridTextAreas,e));
editfield.Layout.Row = 1;
function onValueChanged(gridTextAreas, event)
delete(gridTextAreas.Children);
n = event.Value;
set(gridTextAreas, 'RowHeight', repmat({'fit'},n,1))
for i = 1:n
text = sprintf('This is textarea %i/%i', i, n);
uitextarea(gridTextAreas, 'Value', text)
end
end
Note that in AppDesigner the implementation of the onValueChanged function handle would look different, as you usually pass the app, then the handle of the object generating the callback and then the event data.

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by