필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
mania online
mania online 2016년 4월 30일
편집: Shameer Parmar 2016년 6월 14일
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개)

Geoff Hayes
Geoff Hayes 2016년 4월 30일
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.
  댓글 수: 1
mania online
mania online 2016년 5월 1일
here i attach two files containing command window results and function. can you explain how can i do that..

댓글을 달려면 로그인하십시오.


Shameer Parmar
Shameer Parmar 2016년 6월 14일
편집: Shameer Parmar 2016년 6월 14일
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by