How to get slider value: hObject.Value or get(hObject, 'Value')?

Hello all,
I was reading this page from MATLAB documentation and it gives this example:
function myui()
figure
uicontrol('Style','slider','Callback',@display_slider_value);
end
function display_slider_value(hObject,callbackdata)
newval = num2str(hObject.Value);
disp(['Slider moved to ' newval]);
end
I tried it on version R2014a and it returns the following error at runtime:
Attempt to reference field of non-structure array.
So I looked around and apparantly this is how to get the Value field of an object given the objects handle:
...
slider_val = get(hObject, 'Value');
newval = num2str(slider_val);
...
So my question is, which is it? Why does the documentation uses the .Value field on something that is not a structure? Is that a property specific to version R2015a of MATLAB, that it is possible to reference fields of an object using its handle? Or is it just a typo?
Thank you all very much for reading my question. Any help is greatly appreciated.
Cheers, Puya

 Accepted Answer

The online documentation available through the Support website defaults to the latest release, which may contain functions or functionality that will not work in previous releases. Using graphicsHandle.propertyName to retrieve properties of graphics objects was part of the new graphics system introduced in release R2014b. See this page from the documentation for more information.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!