How to continuously change the plotted data according to the value obtained from a "uislider" component?
21 views (last 30 days)
Show older comments
MathWorks Support Team
on 23 Apr 2020
Answered: MathWorks Support Team
on 27 Apr 2020
The following code should change the y-value of the plotted horizontal line according to the value obtained from the "uislider" component continuously. But the obtained values seem to be incorrect and lagging behind the position of the slider.
f = uifigure('Position',[10 10 500 800]);
a = uiaxes('Parent',f,'Position',[10 10 480 700]);
s = uislider('Parent',f,'Position',[10 760 400 10]);
p = plot(a,[0 4],[4 4]);
s.ValueChangingFcn = @updatePlot;
function updatePlot(src,event)
src.Parent.Children(2).Children.YData(:) = src.Value;
end
Accepted Answer
MathWorks Support Team
on 23 Apr 2020
The issue is resolved by modifying the callback function as follows:
function updatePlot(src,event)
src.Parent.Children(2).Children.YData(:) = event.Value;
end
According the the documentation for "uislider", in order to monitor the continuously changing value of the slider, the callback should use the "Value" property of the "event" argument, and not of the "source" argument. For an example and more details on creating response to a moving slider, please refer to the following documentation link:
0 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!