getpts - can't select multiple points when plot contains datetime axis
11 views (last 30 days)
Show older comments
Time = [datetime('now'):seconds(1):datetime('now')+minutes(1)];
Value = randn(61,1);
plot(Time, Value);
[TimePoints, ~] = getpts;
When I select one point (left-click) and press return, everything is fine. But when I try to select multiple points I get this error message:
Error using datetime/horzcat (line 1292)
All inputs must be datetimes or date/time character vectors or date/time
strings.
Error in getpts>NextButtonDown (line 250)
set([GETPTS_H1 GETPTS_H2], 'XData', [x newx], ...
Error in getpts (line 36)
feval(varargin{:});
Error using getpts (line 108)
Error while evaluating Figure WindowButtonDownFcn.
The getpts documentation says that the output argument is a double. I presume that is the issue. But it will return one datetime value. So I'm hoping there's a way to get it to return more. Is that possible? Or do I have to convert the datetime values to datenum values, make the plot, use getpts and then convert them back again? Thanks.
3 Comments
dpb
on 11 Aug 2018
Edited: dpb
on 11 Aug 2018
Hmmm...I don't have the TB and the TMW search engine didn't locate it and it wasn't at FEX so I didn't know.
This time it did locate...not sure what's up w/ that.
As you say, the doc clearly indicates it expects only a double as its return; it hasn't been updated to handle the overloaded plot functions.
You've got the option you outlined which would be somewhat painful or, since it's an m-file you could look into its handling of returned values and see how complex it might be to add the facility to handle datetime return values; since I don't have TB, can't see the code here to tell.
I don't know how feasible it would be to install a callback routine to trap the returned coordinate to do the conversion; you probably will have to make changes in the function itself but might see if they left a hook available.
Definitely worth at least an enhancement request if not bug report...
ADDENDUM TMW may think since it's in Image Processing TB that images don't have datetime axes...
ginput does return an array of coordinates but I've not yet exactly figured out the x-axes scaling when in datetime coordinates...
Accepted Answer
Image Analyst
on 11 Aug 2018
getpts() is meant to work with images and return x,y values. The two axes are supposed to have the same units, which yours don't, and which is explained by the error message "All inputs must be datetimes or date/time character vectors or date/time strings."
I suggest you use ginput() instead.
3 Comments
dpb
on 11 Aug 2018
Ah! I wasn't aware of num2ruler...name proliferation will eventually sink the ship I'm afraid, it's just not possible to keep track of all the new stuff that keeps showing up...it's hard enough when one has 30 yrs previous experience with the base product and a few TBs; can't imagine how overwhelming it must be to the new user...
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!