Why do I receive an error when evaluating code from the documentation for DATACURSORMODE?

1 view (last 30 days)
When I open the documentation for DATACURSORMODE and evaluate the following code:
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip','SnapToDataVertex','off')
% Click on line to place datatip
c_info = getCursorInfo(dcm_obj);
set(c_info.Target,'LineWidth',2) % Make selected line wider
I receive the following error message:
??? Attempt to reference field of non-structure array.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed in Release 2006a (R2006a). For previous product releases, read below for any possible workarounds:
This is an error in the example in the documentation for DATACURSORMODE. In this example, the DATACURSORMODE property 'Enable' has not been set to 'on' when it should have been.
To resolve this issue, replace the code in the documentation with the following:
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig);
set(dcm_obj,'Enable','on','DisplayStyle','datatip','SnapToDataVertex','off')
% Click on line to place datatip
c_info = getCursorInfo(dcm_obj);
set(c_info.Target,'LineWidth',2) % Make selected line wider
Note that you will need to click on one on the lines and place a datatip before executing the last two lines of code.

More Answers (0)

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!