Clear Filters
Clear Filters

How to Define a Checkbox?

7 views (last 30 days)
Lexington Stoyell
Lexington Stoyell on 6 Feb 2018
Commented: Walter Roberson on 7 Feb 2018
Currently when I run through a code, which I have two checkboxes in, the second is undefined. I was given the original code to update and one of the updates that I made was adding another checkbox. (I made another checkbox using GUIDE.) I have almost an identical method for defining this checkbox, but it says that it is undefined. The results of the checkbox are used in an if statement that determines how the resulting document will be saved.
Checkbox #1 that works: values1 = get(handles.checkbox1,'Value'); if values1 open_system(test_model_name) else load_system(test_model_name) end
My Checkbox: values = get(handles.checkbox2, 'Value'); if values == 0 %...goes into the rest of my statement
Going through the entire code given, the first checkbox is not mentioned anywhere else. How is it defined and the second one not!?!?
  12 Comments
Walter Roberson
Walter Roberson on 7 Feb 2018
That code cannot produce the error message given previously about undefined variable checkbox2 . At best it could have an error about Reference to non-existent field 'checkbox2'
We need your updated code and your current error message.
Walter Roberson
Walter Roberson on 7 Feb 2018
"Going through the entire code given, the first checkbox is not mentioned anywhere else. How is it defined"
It was defined in GUIDE. It lives in the .fig file when not in use, and loading the fig file recreates the graphics object. GUIDE called uicontrol() on your behalf when the GUI was constructed and saved the result in the .fig file.

Sign in to comment.

Answers (1)

Jan
Jan on 7 Feb 2018
The discussion in the comments gets more complicated that the actual problem is.
If you create a checkbox in GUIDE, the corresponding fields in the handles struct and the callback is created automatically. You can check this easily using the debugger and editing the code.
If your code fails, because a certain field in the handles struct is missing or contains unexpected values, this will be a mistake of the programmer. Then the debugger helps to identify, where the wrong value has been written to the handles struct.
Posting screenshots of the code is very inconvenient for the readers. Post the code as text or attach it instead. But it should not be hard to debug the code by your own.
My problem with helping you is the actual question, which I do not understand:
Going through the entire code given, the first checkbox is not mentioned
anywhere else. How is it defined and the second one not!?!?
What is missing where? Do you get an error message? Then please post it.
Previously I had used checkbox2_Callback in attempts to troubleshoot the issue
This sounds like wild guessing. I know this state during programming. It is the perfect time to switch the monitor off and drink a cup of coffee. Some fresh air helps. Afterwards (preferably tomorrow) start the debugging again. It is very likely, that you find a tiny typo like "chekcbox2" or reveal a small wrong assumption.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!