MATLAB Creating Graphical User Interfaces

(ff) #1

  • Creates a callback function called findMethodSelected for the drop-down menu.
    When the value of the drop-down menu changes to 'Quartiles', the callback hides
    the components in second row of grid2 by setting grid.RowHeight{2} to 0.


Create a program file called showhide.m. Then paste this code into the file and run it.


function showhide


f = uifigure('Name','Statistical Analysis');


% Create grid1 in the figure
grid1 = uigridlayout(f);
grid1.RowHeight = {'1x'};
grid1.ColumnWidth= {220,'1x'};


% Add a panel and axes
p = uipanel(grid1);
ax = uiaxes(grid1);


% Create grid2 in the panel
grid2 = uigridlayout(p);
grid2.RowHeight = {22, 22, 22};
grid2.ColumnWidth = {80,'1x'};


% Add method label and drop-down
findMethodLabel = uilabel(grid2,'Text','Find Method:');
findMethod = uidropdown(grid2,'Items',{'Moving median','Quartiles'});
findMethod.ValueChangedFcn = @findMethodSelected;


% Add window size label and spinner
winSizeLabel = uilabel(grid2,'Text','Window Size:');
winSize = uispinner(grid2,'Value',0);


% Add threshold label and spinner
thresLabel = uilabel(grid2,'Text','Threshold:');
thres = uispinner(grid2,'Value',3);


function findMethodSelected(src,~)
method = src.Value;


switch method
case 'Quartiles'
% Collapse the second row (hides winSize spinner)
grid2.RowHeight{2} = 0;


Using Grid Layout Managers
Free download pdf