How to get slider value: hObject.Value or get(hObject, 'Value')?
古いコメントを表示
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
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!