Output not shown in edit text box in GUI

I am trying to write the output(count of detected vehicles) in the edit box. Once I run the GUI, I get those values in the command window, but not in the edit text box. What am I doing wrong?
<<
>>

Answers (2)

Smitha - try converting your numbers (the output of the call to Intelligent_Traffic_Control to strings using num2str
set(handles.edit1,'String',num2str(output1));
I'm assuming that the output variables are numeric...

5 Comments

Hey, thanks for the reply. I've tried using num2str too.. doesn't work that way, either.
Smitha - wait. Why is this code in the edit1_CreateFcn? If you are trying to update the text while this control is being created, then I don't think that this will work.
Please remove this code (to call your Intelligent_Traffic_Control and set the edit controls) and place it in the OpeningFcn of your GUI.
OpeningFcn or OutputFcn?
Place Intelligent_Traffic_Control in whatever callback you want to call it in. Perhaps it's the OpeningFcn() but it might be in the callback of a "Go!" pushbutton that you perhaps push after you've done something like clicked on a video file in a listbox or clicked a button to snap a photo from a camera. I never ever put anything in the CreateFcn() functions. Basically you should just ignore all CreateFcn() callbacks and never put anything into them.
Be sure to see my additional corrections in my answer below.

Sign in to comment.

In addition to the correction Geoff gave you, your set() commands send the outputs all to the SAME edit field control, not different ones. Use different controls:
set(handles.edit1, 'String', num2str(output1));
set(handles.edit2, 'String', num2str(output2));
set(handles.edit3, 'String', num2str(output3));
Also, if you have R2014b or later, do it the modern OOP way:
handles.edit1.String = num2str(output1);
handles.edit2.String = num2str(output2);
handles.edit3.String = num2str(output3);
and make sure call guidata() before the end of the callback since you're changing the handles structure
% Update handles structure
guidata(hObject, handles);

Categories

Asked:

on 15 May 2017

Commented:

on 15 May 2017

Community Treasure Hunt

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

Start Hunting!