Hi, I've a script which takes 2(two) input from the user and generates a plot and a value
%This is the input
currenterror = input('Enter the current error : ');
currentdelerror = input('Enter the current delerror : ');
%Program Starts
%Program Ends
a = FinalOut;
Then it produces a plot something like this
Now I want the user to have a slider input for both 'currentdelerror' & 'currenterror'
How can I do that?

 Accepted Answer

Walter Roberson
Walter Roberson on 12 Nov 2016

1 vote

Use uicontrol('style', 'slider') to create the two sliders, giving appropriate Position and Value and Min and Max and SliderStep parameters.
When you want to find out what the current values are, get() the Value property of the uicontrols.
You might want to add a 'Plot' pushbutton, uicontrol('Style','push'), which has as its Callback some code to get() the Value properties and to run the code with those values.

3 Comments

Sarit  Hati
Sarit Hati on 13 Nov 2016
Edited: Sarit Hati on 13 Nov 2016
Walter Thank you for your help but sorry I didn't understand (Yes!! I am more dumber than you think ;) )
Suppose
P1 = input('Play with 1 : ');
x=0:0.01:10;
y=sin(P1*x);
plot(x,y);
Then what will be the exact script for that?? Thanks in advance!
ax = gca();
old_units = get(ax, 'Units');
set(ax, 'Units', 'Pixels');
ax_pos = get(ax, 'Position');
set(ax, 'Units', old_units);
markline = line(nan, nan, 'Parent', ax, 'Tag', 'MarkerLine');
slider_pos = [ax_pos(1) + 30, ax_pos(2) - 20, ax_pos(3) - 60, 30]; %you will need to fiddle with the numeric constants
slider = uicontrol('Style', 'slider', 'Units', 'Pixels', 'Position', slider_pos, 'Value', 5, 'Min', 0, 'Max', 10, 'Callback', {@YourCallbackRoutine, markline});
YourCallbackRoutine(slider, [], ax);
function YourCallbackRoutine(hObject, event, markline)
ax = ancestor(markline, 'axes');
YL = get(ax, 'YLimit');
Ylow = YL(1);
Yhigh = mean(YL);
sp = get(hObject, 'Value');
set(markline, 'XData', [sp sp], 'YData', [Ylow, Yhigh], 'Color', 'red')
This figures out where the current axis is, inserts a slider below the axis, sets up a callback routine and invokes the routine (to trigger its action). It also inserts a line object into the axes. The callback reads the current slider position and moves the line to that x position, configuring the line from the bottom margin to half way to the top margin
Sarit  Hati
Sarit Hati on 13 Nov 2016
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!