Moving a structure into a gui

1 view (last 30 days)
Sergio Gutierrez
Sergio Gutierrez on 24 Apr 2014
Answered: Walter Roberson on 24 Apr 2014
I'm trying to get questions(1).text into a static text box in a gui. After clicking on he push button the structure appears in the command window, but I can't get it to appear in the static text box. The static text box is tagged Text_1, but I keep getting an error saying that Text_1 is undefined.
function ptn1_Callback(hObject, eventdata, handles)
handles.questions(1).text = 'Amino acids are all composed of an amine group, a carboxyl group, a hydrogren, and an R group. Which group determines the chemical reactivity and solubility of the amino acid? ';
handles.questions(1).rightanswer = 'The R group';
handles.questions(1).wronganswer1 = 'The hydrogden';
handles.questions(1).wronganswer2 = 'The amine group';
handles.questions().wronganswer3 = 'The carboxyl group';
x = randi(1);
handles.questions(randi(x))
set(handles.Text_1,'String',handles.questions(randi(x)).text)
This is the error message.
Reference to non-existent field 'Text_1'.
Error in Hopeful_game>ptn1_Callback (line 97)
set(handles.Text_1,'String',handles.questions(randi(x)).text)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Hopeful_game (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Hopeful_game('ptn1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Answers (1)

Walter Roberson
Walter Roberson on 24 Apr 2014
If you create the field handles.Text_1 dynamically, then before the end of the function you create it in, you need to
guidata(gcf, handles);

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!