How to get slider value: hObject.Value or get(hObject, 'Value')?
Show older comments
Hello all,
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
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!