MATLAB: Do I receive an error when evaluating code from the documentation for DATACURSORMODE

cursordataenableMATLABmodeobject

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.

Best Answer

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.