필터 지우기
필터 지우기

1대 n으로 대응을 시키는 방법이 있나요?

조회 수: 2 (최근 30일)
대윤
대윤 2022년 12월 7일
답변: Divyanshu 2023년 3월 24일
위 예제를 보고 참고하며 코드를 작성하고 있는데
function dataselection
fig = uifigure('Position',[100 100 350 275]);
% Create Numeric Edit Field
ef = uieditfield(fig,'numeric',...
'Position',[125 90 100 22]);
% Create List Box
lbox = uilistbox(fig,...
'Items', {'Freezing', 'Warm', 'Hot', 'Boiling'},...
'ItemsData', [0, 25, 40, 100],...
'Position',[125 120 100 78],...
'ValueChangedFcn', @selectionChanged);
% ValueChangedFcn callback
function selectionChanged(src,event)
% Display list box data in edit field
ef.Value = src.Value;
end
end
위 코드에서
'Items', {'Freezing', 'Warm', 'Hot', 'Boiling'},...
'ItemsData', [0, 25, 40, 100],...
items와 itemsdata는 1대1로 대응이 되는데 예를들어서
freezing - 0,1,2,3,4
warm - 20,21,22,23,24,25,26,27
과 같이 하나의 item에 여러개의 itemdata를 대응시킬수 있을까요?

답변 (1개)

Divyanshu
Divyanshu 2023년 3월 24일
Directly it is not possible to achieve this 1 to n mapping from the function of uilistbox itself.
But you can have a look at the below demo script which can be a possible work around.
function dataselection
fig = uifigure('Position',[100 100 350 275]);
% Create Numeric Edit Field
ef = uitextarea(fig,...
'Position',[125 90 100 22],...
'Value','');
% Create List Box
lbox = uilistbox(fig,...
'Items', {'Freezing', 'Warm', 'Hot', 'Boiling'},...
'ItemsData', ['F', 'W', 'H', 'B'],...
'Position',[125 120 100 78],...
'ValueChangedFcn', @selectionChanged);
% ValueChangedFcn callback
function selectionChanged(src,event)
% Display list box data in edit field
switch src.Value
case 'F'
val = {'0' '1' };
case 'W'
val = {'20' '21'};
case 'H'
val = {'45' '46'};
case 'B'
val = {'100' '101'};
end
ef.Value = val;
end
end

카테고리

Help CenterFile Exchange에서 uifigure 기반 앱에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!