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

1 次查看(过去 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!