Picking exact data on a plot with ginput

I plot a line with experimental data (x,y). Then I want to pick, with ginput, EXACTLY, some of the data on the graph. Is it possible? How can be done?

Respuestas (1)

Adam Danz
Adam Danz el 25 de Oct. de 2019

1 voto

See this answer. It shows two methods of obtaining the coordinates of a data point by clicking on it. The ginput() idea is explained in method #2. If you have any other quesitons, feel free to comment here (or in that link).

15 comentarios

Luigi Sambuelli
Luigi Sambuelli el 25 de Oct. de 2019
Thank you, i really did skrew my problem following this suggestion. But...
Luigi
Adam Danz
Adam Danz el 25 de Oct. de 2019
Sorry, I didn't understand. Did you come across a new problem or is there a problem with the implementation of the proposed solution? I'd be glad to help out.
Adam Danz
Adam Danz el 25 de Oct. de 2019
Luigi Sambuelli 's answer moved here as a comment.
MMM sorry, I was "obscure". I need to find some points on a graph (that have to be some of the "experimental points" used to make the graph) in order to calculate a detrending broken line (detrend command does not work because the signal is "unbalanced" around zero, yet nearly periodic). The point is that I do not know in advance how many points I will select to build these detrending lines... It's a messy problem..
Thank you anyway for your suggestion.
Luigi
Adam Danz
Adam Danz el 25 de Oct. de 2019
If you can formalize the problem or perhaps map it out in a diagram I might be able to help further.
Adam Danz
Adam Danz el 28 de Oct. de 2019
Luigi Sambuelli's answer moved here as a comment.
Thank you Adam for your efforts. In the attached figure you'll see some of the signals I've to detrend. Thank you anyway.
Luigi
FigureA.bmp
Adam Danz
Adam Danz el 28 de Oct. de 2019
@ Luigi Sambuelli, please use the comment section for comments and the answer sections for answer.
________________________________________________
In your original quesiton, you wanted to use ginput() to choose a datapoint on the graph and it looks like you're trying to determine where your two datasets start to bifurcate. Is this still your goal?
It's unclear whether you're still seeking help on this topic. If you are, I'd be glad to help but I need to understand exactly what the goal is.
Adam Danz
Adam Danz el 28 de Oct. de 2019
@Luigi Sambuelli 's answer moved here as a comment.
_______________________________________________
The two signal in the figure are measured independently by two sensors in two different places. Both of them have a drift (that sometimes is a broken line, not a straight line fron the beginning to the end). Each drift is different from the others. I'm trying to remove these dirfts. The matlab DETREND command does not work in this case because, searching for the liast square interpolating line, it works badly with signals that "have no zero mean around their linear trend". In this case the interpolating line takes into account the minima. My idea is to pick 2 points in the linear parts of the graphs, calculate a straight line passing in these two points and subtract this straight line to the original data. In fact the linear part in the signals shoul be horizontal i.e. have a costant value. That's why I was looking for a way to pick exactly two data points.
LS
Adam Danz
Adam Danz el 28 de Oct. de 2019
Editada: Adam Danz el 28 de Oct. de 2019
Hmmm I've never used detrend() but I took a look at that documentation and does seem like it would be the function to use in this problem.
Your idea to pick 2 points in the linear parts of the graph is subjective and therefore not generalizable to other sets of data. Instead, have you tried using the "break point" (bp) option in detrend()? y = detrend(x,n,bp)
"DETREND command does not work in this case because, searching for the liast square interpolating line, it works badly with signals that "have no zero mean around their linear trend""
Would you happen to have a plot that shows the results along with whatever input options you used in detrend()? I'm curious what "works badly" looks like.
Please use the link below that reads "Comment on this Answer" unless you are proposing a solution to your question.
Luigi Sambuelli
Luigi Sambuelli el 29 de Oct. de 2019
Here two signals: before and after detrend. An offset is clearly visible. In my opinion it comes from
y = detrend(x) removes the best straight-line fit
and it does this even if you select 2 or 3 break points between each consecutive couple of points.
Adam Danz
Adam Danz el 29 de Oct. de 2019
One possibility is that the trend isn't linear. The slope of the 2nd rise in your black data seems to be slightly larger than the slope in the 1st rise.
My first suggestion would be to try to optimize your detrend() inputs. What breakpoints did you use?
My 2nd suggestion would be to break up your data into two segments: 1) all data prior to the the jump-up at around the 1st week of Feb 2018 and 2) data the follow that point; and then to run detrend on each segment of data.
Luigi Sambuelli
Luigi Sambuelli el 30 de Oct. de 2019
Indeed I selected 2 break points (bp) obtaining 3 interpolating lines: one before the first bp, the second between the 2 bp and the 3 bp and the last from the 3 bp to the end of the signal. But, as you wriote (and I agree absolutely with you) the choice of the break point are "empirical". I'm afraid that this is a kind of "hill posed" problem. Thank you very much for the time you spent around my stuff.
Adam Danz
Adam Danz el 30 de Oct. de 2019
No problem - I enjoy it ;)
Depending on how much time you have to play around with the data, you might try breaking up the data into ~3 segments and applying detrend() to each, and then stitch them back together.
Smoothed.jpg
Luigi Sambuelli
Luigi Sambuelli el 30 de Oct. de 2019
Yeah this is exactly what I've been doing for the last 2 or 3 weeks :-)
Thank you very much again.
Luigi
Luigi Sambuelli
Luigi Sambuelli el 30 de Oct. de 2019
Grrrrrrrrr
Thanks, nice and true!

Iniciar sesión para comentar.

Preguntada:

el 25 de Oct. de 2019

Comentada:

el 30 de Oct. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by