programmatic GUI callback function

3 ビュー (過去 30 日間)
Chandrasekhar
Chandrasekhar 2014 年 12 月 24 日
コメント済み: Chandrasekhar 2014 年 12 月 24 日
I want to access the GUI control from the call back function. how can I do this. I got the below code from Matlab help but it gives an error when executed. How can I access the slider from the call back function.
function mygui()
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

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 12 月 24 日
Akshata - what is the error message? Note that if you are trying to get the current value of the slider, you could try using
newval = num2str(get(hObject,'Value'));
The above assumes that the error has something to do with the current line that gets the newval.
  3 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 12 月 24 日
The error message is indicating that you are trying to access a field of an object that is not a structure. In your case, hObject is not a structure and so you can't access Value from it. Which version of MATLAB are you using?
To get around this error, replace your line with
newval = num2str(get(hObject,'Value'));
as described above.
Chandrasekhar
Chandrasekhar 2014 年 12 月 24 日
Thanks for the reply. It worked I am using 2012b

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2014 年 12 月 24 日
I fyou're using a version of MATLAB < R2014b, hObject.Value won't work. That syntax is added in R2014b.
If your company/university if current on maintenance, you should be able to upgrade at no additional cost. If not, use get(hObject,'Value')
  1 件のコメント
Chandrasekhar
Chandrasekhar 2014 年 12 月 24 日
thanks, it worked

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by