I want to display the results shown in command window by clicking push button
3 views (last 30 days)
Show older comments
I want to display the results shown in command window by clicking push button. I mean, I created a function and when I run that function the results are shown in matlab command window. Now I am making an interface with matlab gui and want to show that result in a textbox by clicking push button. For that i call this function in gui but getting results in command window . How can i redirect results from command window to GUI textbox? Results containing numbers as well as words (about 5 lines).
Answers (2)
Geoff Hayes
on 30 Apr 2016
mania - your function will have to return the string data (that is currently being written to the console) so that the pushbutton callback (which invokes the function) can take this output and set in to the text control on your GUI.
Shameer Parmar
on 14 Jun 2016
Edited: Shameer Parmar
on 14 Jun 2016
Hi Mania,
In order to achieve your requirement, you have to do following changes:
1. In your function file (in which the results are getting created and displayed in command window), check in which line the result is getting displayed. and suppress it from getting displayed in command window. The simple way to do this is, keep semicolon for each command.
2. Now this 'results' variable is you creating in function workspace, so it should get creating in base workspace, so that it get access by GUI. for this add following command in your function file before end.
assignin('base','results',results);
3. Now, as you want to display the results, which is in structure format, you need listbox. But you are using the textbox, so with text box, it wont be possible to display your results. Kindly edit your GUI and replace the 'textbox' with 'listbox' (or create a new GUI, it is easy.)
4. now, in callback of push button, apply following logic, to display the result in GUI list box.
xyx;
results = evalin('base','results');
field = fields(results);
newResult = {};
for count = 1: length(field)
newResult{count} = [char(field(count)),': ',num2str(getfield(results,char(field(count))))];
end
newResult = newResult';
set(handles.listbox1,'string',newResult);
Please find attached for more details. Let me know if you face any issue.
0 Comments
See Also
Categories
Find more on Environment and Settings 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!