GUI sliders that update a plot and create a subsection of data

3 次查看(过去 30 天)
I am trying to create a GUI with uicontrol with sliders that will go on to section up my dataset depending on where the user sets the sliders on the data, How can I do this and use the values set by the user to trim down my dataset and use the smaller dataset for the rest of my function? This is what I have created so far
sldplot=plot(data)
btn = uicontrol('Style', 'pushbutton', 'String', 'Clear','Position', [20 20 50 20],'Callback', 'cla');
sld = uicontrol('Style', 'slider','Min',1,'Max',n,'Value',41,'Position', [400 20 120 20],'Callback', @plotxlim);
sld2 = uicontrol('Style', 'slider','Min',1,'Max',n,'Value',41,'Position', [200 20 120 20],'Callback', @plotxlim);
txt = uicontrol('Style','text','Position',[400 45 120 20],'String','First cut');
txt2 = uicontrol('Style','text','Position',[450 50 125 25],'String','Second cut');
addlistener(sld,'ActionEvent',@(sldObject, event) makeplot(sldObject, event,xn,sldplot));
addlistener(sld2,'ActionEvent',@(sld2Object, event) makeplot(sld2Object, event,xn,sldplot));
n2 = get(sldObject,'Value');
n3 = get(sld2Object, 'Value');
set(sldplot,'ydata',x.^n);
drawnow;
but there is some issues I keep getting an error saying that 'ActionEvent' is not defined for class 'matlab.ui.control.UIControl'. Also I am not sure how to use this to then create a new subset of data.

回答(1 个)

Jan
Jan 2015-3-16
Since Matlab 2014a the event has a new name:
addlistener(hSlider, 'ContinuousValueChange', @myCallbackFcn);
It is not clear how you define "a new subset of data". Therefore I cannot answer the 2nd question.
  2 个评论
Bran
Bran 2015-3-16
Apologies, I wasnt very clear. If they define the subset by placing the sliders half way along the plot then I would like for the new Dataset to be (500:n) if for example they chose to place the slider at 500 and the other slider at the end of the dataset (n). Just to be clear in the code above n is the length of my initial Dataset
Bran
Bran 2015-3-16
Also just a side not has the plotxlim changed also as I have the follwing error after rectifying the one above;
Undefined function 'plotxlim' for input arguments of type 'matlab.ui.control.UIControl'.
Error while evaluating UIControl Callback

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by