How can I use slider value in push button area, to generate a function.

function t_1_Callback(hObject, eventdata, handles)
a=get(handles.t_1,'value');
set(handles.slider_editText,'string',num2str(a));
guidata(hObject,handles);
a=str2num(a);
.
.
.
.
function on_switch_Callback(hObject, eventdata, handles)
H01=[cosd(a), 0, sind(a), 30*cosd(a); sind(a), 0, -cosd(a), 30*sind(a); 0, 1, 1,30; 0,0,0,1];

댓글 수: 3

You haven't told us what your code is doing or what the various things are it refers to or what you are actually wanting to do. Which is your pushbutton? Which is the slider? What is the problem with just refering to the slider as you would any other control, by its tag, as you already do in t_1_Callback?
Here, t_1 is the tag name of the slider button,I set a maximum and minimum range for that slider. when the slider will slide in between the range, I want to restore the value in the parameter 'a' and that value to use in the function of the push button. The 'on_switch' is the push button. But I can not use the value. Actually may be the value is not updating by my syntax.
Either do as Geoff Hayes shows or you need to save
handles.a = ...
guidata( hObject, handles )
in your slider callback and then
a = handles.a
in your pushbutton callback, but on the whole there really isn't much point constantly updating a variable on handles when you can just get it direct from the slider when you need it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Tonusree - if you want to use the a value in your pushbutton callback (is this on_switch_Callback?) then just do
function on_switch_Callback(hObject, eventdata, handles)
a=get(handles.t_1,'value');
H01=[cosd(a), 0, sind(a), 30*cosd(a); sind(a), 0, -cosd(a), 30*sind(a); 0, 1, 1,30; 0,0,0,1];
% etc.
end

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2019년 3월 7일

댓글:

2019년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by