Assuming the x and y sliders adjust x-axis limit and y-axis limit of the plot respectively, following lines of code shows one of the possible solution to the problem.
The app contains dropdown, x-slider, y-slider, axes and a button. Dropdown enables selection of signals, i.e, either sin or cos. The x-slider and y-slider adjusts the x-axis limit and y-axis limit of the axes. Clicking on the push-button generates signal plot with axes limits as specified.
App variables required to hold user input are:
properties (Access = private)
func; % variable to hold the signal selected from dropdown
xslider; % variable to hold upper limit of xlim
yslider; % variable to hold upper limit of ylim
end
Startup function callback saves default values of dropdown and sliders into app variables.
function startupFcn(app)
app.func= str2func(app.SignalDropDown.Value); %str2func creates function handle from string
app.xslider= app.XSlider.Value;
app.yslider= app.YSlider.Value;
end
Signal dropdown callback function saves the user selected signal into app variable 'func'.
function SignalDropDownValueChanged(app, event)
value = app.SignalDropDown.Value;
app.func= str2func(value);
end
Pushbutton callback function holds the x, y values, generates the plot and sets xlim and ylim as per user input.
function EnterButtonPushed(app, event)
x=0:0.01:(360/180)*pi;
y= app.func(x);
plot(app.UIAxes,x,y);
xlim(app.UIAxes,[0 app.xslider]);
ylim(app.UIAxes,[-2 app.yslider]);
end
Slider callback functions saves user input into app variables 'xslider' and 'yslider'.
function XSliderValueChanged(app, event)
app.xslider = app.XSlider.Value;
end
function YSliderValueChanged(app, event)
app.yslider = app.YSlider.Value;
end
All components can be placed in the app as per user requirement. Refer this link to read more about 'str2func' function.