Datatip not working. Changing location??
9 次查看(过去 30 天)
显示 更早的评论
I cannot click on my graph for some wierd reason but whatever i just assumed i could use the datatip command to show the max of my graph.
When i wrote the code the location of DataTip changes for some wierd reason.
Any ideas?
I posted my code blow
heres the value of the variables
m0 = [ 41 91 331]
This is the frequency of the plot
f0 = [ 1 2 0.3]
This is the amplitude of the graph
This the command window it reads:
ans =
DataTip (X 0, Y 3.399e-16) with properties:
Why is it changing the location of the DataTip??
p= plot(f,P1);
m0=find(P1>0.1)
f0=P1(:,[m0])
datatip(p,f0,m0)
回答(1 个)
Walter Roberson
2020-9-17
You are passing in vectors of x and y coordinates, but datatip is only defined for scalar x and y.
In terms of your plot, f is your independent variable and P1 is your dependent variable. You are extracting some of the P1 entries and passing them in as x coordinates to datatip, and you are passing in indices as your y coordinates to datatip.
When you pass in x and y coordinates, datatip is defined to place the datatip at the nearest point to what you pass in.
You should be passing in f(m0(1)) as your x and f0(1) as your y to datatip()
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!