How to highlight a datapoint on comet using a slider
2 views (last 30 days)
Show older comments
Hi all,
I'm very stuck with how to link a slider to a comet plot i have.
What I intend to do is, the user (once the graph has been plotted) can move the slider back and forwards which will highlight a corresponding coordinate on the graph with a label showing the data (x,y) for that point.
I would like to mention that i am a complete novice so please excuse the embarrasing code...
The current code (including all the previosuly tried code shown in comments) is:
comet(x,y,0.1) %this is the plot style currently
app.Slider.Limits = [0 max(x)]
hold(app.Graph,'on')
% function app.Slider.ValueChangingFcn
% change = comet(app.Graph,x,y,0.1)
% sld = app.Slider(app.Graph,'ValueChangingFcn',@(sld,event) sliderMoving(event,change))
% end
%
% function sliderMoving(event,change)
% [~,ind] = min(abs(x-XData))
% coord = sprintf('%f,%f',XData,YData)
% text(app.Graph,x(ind),y(ind),coord)
% end
% function sliderchanging
% changingValue = event.Value;
function sliderchanging(app, event)
b = app.Slider.Value
%YData = y(XData)
%X = num2str(XData)
%Y = num2str(YData)
%b = char2num(app.Slider.ValueChangedFcn)
[minValue, closestIndex] = min(abs(x - b.')) %this shows an error for
XData = x(closestIndex)
YData = y(x==XData)
%[~,ind] = min(abs(x=XData))
coord = sprintf('\leftarrow %.1f,%.1f',XData,YData)
text(app.Graph,x(XData),y(XData),coord)
plot(app.Graph,x(XData),y(XData),'ko')
end
%plot(app.Graph,x(x==app.Slider.Value),y(x==app.Slider.Value));
% XData = app.Slider.Value
% YData = y(x==XData)
% X = num2str(XData)
% Y = num2str(YData)
% coord = sprintf('%f,%f',XData,YData)
% text(app.Graph,x(x==XData),y(x==XData),coord)
%datatip(co,x(x==app.Slider.Value),y(x==app.Slider.Value))
%position = app.Slider.Value
%ypos = y(x==position)
%xpos = x(x==position)
%text(app.Graph,xpos,ypos,'\leftarrow %.2f,%.2f',xpos,ypos)
Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output 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!