I want to display the results shown in command window by clicking push button.
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
CS Researcher
2016-4-30
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 个评论
CS Researcher
2016-5-1
Can you share your code? It will be easier to debug. It is very hard to understand otherwise.
Shameer Parmar
2016-6-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!