Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

togglebutton with togglebutton inside for afteruse control

조회 수: 2 (최근 30일)
Kuang-Yu WANG
Kuang-Yu WANG 2018년 12월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
hi, I have a problem when dealing with toggle button control. I use one togglebutton2 to deside whether the mechine is on or off after use. togglebutton1 to control the system runing or stop. When the togglebutton1 value = 0, it should read the value of togglebutton2 to decide the mechine is on or off. But the command line just show
Error using handle.handle/get
Invalid or deleted object.
Error in pump_Callback (line 152)
if get(GUI.tot+28, 'value') == 1
Error while evaluating UIControl Callback.
my codes are
if get(togglebutton1, 'value') ==0
set(hObject,'BackgroundColor',GUI.menucolor,...
'string',[get(hObject, 'UserData') ' stopped'],'FontSize',8);
if check == GUI.tot+5 %the value control speed
GUI.p1Running = 0;
if get(togglebutton2, 'value') == 1
stop(p1.t);
vc = vc_set_bits_ac(vc, p1.num, [0 0 0 0 0 0]);
elseif get(togglebutton2, 'value') == 0
stop(p1.t);
vc = vc_set_bits_ac(vc, p1.num, [0 0 0 0 0 0]);
end
end
end
But the code can work well when they are the following one. How can I do? Please Help! Very Thank!
if get(togglebutton1, 'value') ==0
set(hObject,'BackgroundColor',GUI.menucolor,...
'string',[get(hObject, 'UserData') ' stopped'],'FontSize',8);
if check == GUI.tot+5 %the value control speed
GUI.p1Running = 0;
stop(p1.t);
vc = vc_set_bits_ac(vc, p1.num, [0 0 0 0 0 0]);
end
end
  댓글 수: 1
Jan
Jan 2018년 12월 20일
The line if get(GUI.tot+28, 'value') == 1 occurs in the error message, but not in the shown code. Please post the code, you are actually running, not any otehr code.
Are you sure that GUI.tot+28 is meaningful? We cannot know, what the variables check and GUI.tot are.

답변 (1개)

Cris LaPierre
Cris LaPierre 2018년 12월 20일
편집: Cris LaPierre 2018년 12월 20일
I'm with Jan. Your error is coming from code you have not shared.
if get(GUI.tot+28, 'value') == 1
The get function expects the first input to be an object. Basically, a handle to an object. It would appear from your code GUI.tot is a number and not an object handle. So the error is that it cannot find the specified object because either your object handle is invalid or the object has been deleted.
A more typical expression would be
if get(togglebutton1, 'value') == 1
  댓글 수: 2
Kuang-Yu WANG
Kuang-Yu WANG 2018년 12월 22일
ah... sorry my fault. Actually GUI.tot+28 is togglebutton1. Because I do not want to make the question be too complex then I change the name of them.
Walter Roberson
Walter Roberson 2018년 12월 22일
Better to post the actual code.
If you are running R2014a or earlier, then GUI handles are numeric, and adding a number to them would create another numeric value. It is valid in those releases to get() passing in a numeric value -- it is just that the result would seldom just happen to be another valid object handle. It is not impossible to build a situation in those releases such as
GUI.tot = figure(); GUI.fig2 = figure(GUI.tot+35);
but it is seldom a good idea.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by