TipWhen using a button control in a live script, consider setting the Run field for all
other controls in the live script to None. Then, the code only runs when the user clicks
the button control. This can be useful when the live script requires multiple control
values to be set before running the code.
Create Live Script with Multiple Interactive Controls
This example shows how you can use interactive controls to visualize and investigate
patient data in MATLAB®. The example plots the height versus the weight of either male
or female patients, and highlights the patients over a specified height and weight.
Use the interactive controls to specify the gender of the patients to plot, as well as the
threshold height and weight. To view and interact with the controls, open this example in
your browser or in MATLAB.
load patients
thresholdHeight = 68; % Slider with min=60, max=70, step=1
thresholdWeight = 132; % Slider with min=111, max=202, step=1
selectedGender = "Female"; % Drop down with options "Male", "Female"
overThresholdWeights = Weight(Gender==selectedGender & Weight>=thresholdWeight & Height>=thresholdHeight);
overThresholdHeights = Height(Gender==selectedGender & Weight>=thresholdWeight & Height>=thresholdHeight);
sp1 = scatter(Height(Gender==selectedGender),Weight(Gender==selectedGender),'blue');
hold on
sp2 = scatter(overThresholdHeights, overThresholdWeights,'red');
hold off
title('Height vs. Weight of ' + selectedGender + ' Patients')
legendText = sprintf('Patients over %d inches and %d pounds.',thresholdHeight,thresholdWeight);
legend(sp2,legendText,'Location','southoutside')
19 Live Scripts and Functions