I want to display the results shown in command window by clicking push button.

조회 수: 10 (최근 30일)
mania online
mania online 2016년 4월 30일
답변: Shameer Parmar 2016년 6월 10일
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).

답변 (2개)

CS Researcher
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
mania online
mania online 2016년 5월 1일
Error using set error: mxArray must be double, char, or cell Error in GUI2>pushbutton4_Callback (line 126) set(handles.edit4,'String',str);
CS Researcher
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
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.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by