Using an Edit Box as an output in a GUI
9 views (last 30 days)
Show older comments
Hello all!
I've been attempting to create a GUI that does 3 things.
1. Push a 'push button'
2. Load a .m file
3. Put the contents of that .m file as an 'output' into an edit text box.
The .m file (which is called TestAll) returns one value - a string called "ProbDiag." Now I'm trying to make it that whenever you click the button, the value of ProbDiag (where ProbDiag = 'Sinus Tachycardia') is outputted into the edit box.
The .m file is being brought in completely fine, but I'm running into issues 'pushing' that value into the edit box. Any help??? the 2 callback function codes are attached below
% --- Executes on button press in test_button.
function test_button_Callback(hObject, eventdata, handles)
% hObject handle to test_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
TestAll; %runs the .m file called TestAll as long as it's in the same directory
function results_Callback(hObject, eventdata, handles)
% hObject handle to results (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of results as text
% str2double(get(hObject,'String')) returns contents of results as a double
set(handles.results, 'String',ProbDiag)
1 Comment
Jan
on 28 Apr 2016
Does it matter how the variable is called, which carries the output of the function? You do not have to call it "ProbDiag", when I understand the problem correctly.
Answers (3)
Image Analyst
on 28 Apr 2016
You say TestAll() returns one value - a string called "ProbDiag." but you don't even accept it as a return value and then you don't do anything with it. Make the function do this:
% --- Executes on button press in test_button.
function test_button_Callback(hObject, eventdata, handles)
% hObject handle to test_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ProbDiag = TestAll; %runs the .m file called TestAll as long as it's in the same directory
% Put ProbDiag string into the results control
handles.results.String = ProbDiag;
1 Comment
Jan
on 28 Apr 2016
And store the handles struct in the GUI afterwards:
guidata(hObject, handles);
Jan
on 28 Apr 2016
function test_button_Callback(hObject, eventdata, handles)
handles.Result = TestAll;
guidata(hObject, handles);
function results_Callback(hObject, eventdata, handles)
handles = guidata(hObject); % I assume we need this here for the current value
set(handles.results, 'String', handles.Result)
2 Comments
Jan
on 2 May 2016
@nick: If your file "TestAll.m" is a script file (this means, that it does not start with "function ...", you cannot assign an output variable as in handles.Result = TestAll . Scripts do not have outputs. Look for "scripts" and "functions" in the documentation.
See Also
Categories
Find more on Encryption / Cryptography 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!