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)
  3 个评论
John Emberson
John Emberson 2020-9-17
ans =
1 1001
result from size(P1)
i did it like that through my initial trial and error process and just never changed it back because
f0=P1([m0])
provides the same result as
f0=P1(:,[m0])
John Emberson
John Emberson 2020-9-17
I also did transpose(P1) which resuluted in exactly the same thing.
Just incase it was becasue it was a problem with a column vector.
Also the problem is not with the results of find, its with datatip.
Find is finding the numbers i want.
F0 and m0 are the correct values. I am just trying to get them to showup on the graph because I keep having problems when i try to click on the graph. Unsure if its lag or what but I was jsut trying to use datatip to work around that.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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()
  1 个评论
John Emberson
John Emberson 2020-9-17
So that kind of worked. I just make three different x variables and 3 different y variables and plugged into 3 data tips.
(41,1)
(91,2)
(331,0.3)
but now all three datatips state:
DataTip (X 90, Y 2) with properties:
DataIndex: 91
They are all plotting point 2 for some reason

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by