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?

 채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 12일

1 개 추천

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

Sarit  Hati
Sarit Hati 2016년 11월 13일
편집: Sarit Hati 2016년 11월 13일
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 2016년 11월 13일
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 2016년 11월 13일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2016년 11월 12일

댓글:

2016년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by