Info

This question is closed. Reopen it to edit or answer.

togglebutton with togglebutton inside for afteruse control

1 view (last 30 days)
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 Comment
Jan
Jan on 20 Dec 2018
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.

Answers (1)

Cris LaPierre
Cris LaPierre on 20 Dec 2018
Edited: Cris LaPierre on 20 Dec 2018
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 Comments
Kuang-Yu WANG
Kuang-Yu WANG on 22 Dec 2018
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 on 22 Dec 2018
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!