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

1 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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.

更多回答(0 个)

产品


版本

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by