How to highlight a datapoint on comet using a slider

조회 수: 3 (최근 30일)
Anon
Anon 2021년 1월 16일
댓글: Cris LaPierre 2021년 1월 16일
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)

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by