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?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Nov. de 2016

1 voto

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 comentarios

Sarit  Hati
Sarit Hati el 13 de Nov. de 2016
Editada: Sarit Hati el 13 de Nov. de 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!
Walter Roberson
Walter Roberson el 13 de Nov. de 2016
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 el 13 de Nov. de 2016
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 12 de Nov. de 2016

Comentada:

el 13 de Nov. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by