Datatip not working. Changing location??

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 commentaires

What is size(P1) ?
f0=P1(:,[m0])
implies it might have multiple rows. If P1 is not a row vector then find() is returning linear indexing not column indexing.
John Emberson
John Emberson le 17 Sep 2020
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 le 17 Sep 2020
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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 17 Sep 2020

0 votes

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 commentaire

John Emberson
John Emberson le 17 Sep 2020
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

Connectez-vous pour commenter.

Catégories

Produits

Version

R2019b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by