I want to display the results shown in command window by clicking push button.
16 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).
0 Comments
Answers (2)
CS Researcher
on 30 Apr 2016
You should always share some code with questions like these. Lets say the handle to the textbox is 'display_text' and the output of the pushbutton_Callback is a string str, you can use the following:
function pushbutton_Callback(hObject, eventdata, handles)
str = 'something'; % Whatever is the output
set(handles.display_text,'String',str);
3 Comments
CS Researcher
on 1 May 2016
Can you share your code? It will be easier to debug. It is very hard to understand otherwise.
Shameer Parmar
on 10 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; % to call your function file
results = evalin('base','results'); % to copy the results from base workspace to functions Workspace.
field = fields(results); % to list of the fields of structre of your results.
newResult = {}; % to create new blank array variable for displayint results.
for count = 1: length(field) % to create new variable to dispay result into GUI field
newResult{count} = [char(field(count)),': ',num2str(getfield(results,char(field(count))))];
end
newResult = newResult'; % to convert row array to column array.
set(handles.listbox1,'string',newResult); % to display into GUI.
Please find attached for more details. Let me know if you face any issue.
0 Comments
See Also
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!