Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
대윤
대윤 el 7 de Dic. de 2022
Respondida: Divyanshu el 24 de Mzo. de 2023
위 예제를 보고 참고하며 코드를 작성하고 있는데
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를 대응시킬수 있을까요?

Respuestas (1)

Divyanshu
Divyanshu el 24 de Mzo. de 2023
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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!