You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Picking exact data on a plot with ginput
12 views (last 30 days)
Show older comments
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?
Answers (1)
Adam Danz
on 25 Oct 2019
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 Comments
Luigi Sambuelli
on 25 Oct 2019
Thank you, i really did skrew my problem following this suggestion. But...
Luigi
Adam Danz
on 25 Oct 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
on 28 Oct 2019
________________________________________________
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
on 28 Oct 2019
_______________________________________________
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
on 28 Oct 2019
Edited: Adam Danz
on 28 Oct 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
on 29 Oct 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
on 29 Oct 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
on 30 Oct 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
on 30 Oct 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.

Luigi Sambuelli
on 30 Oct 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
on 30 Oct 2019
Grrrrrrrrr
Thanks, nice and true!
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
