How to show total execution time using MATLAB GUI

조회 수: 7 (최근 30일)
Tania
Tania 2015년 8월 26일
답변: Joseph Cheng 2015년 8월 26일
Hi everyone,
I need some help to show total execution time on a static text box using MATLAB GUI. Previously I was using tic and toc but for MATLAB gui not sure how to do that.
Any help will be appreciated.
  댓글 수: 4
Mathieu
Mathieu 2015년 8월 26일
편집: Mathieu 2015년 8월 26일
So, you have to create a text box on your GUI, named it with a specific Tag, and in your code you just have to change the string of this text box.
At the beginning of your code, you first look for the handle of the text box in your GUI with the findobj function and using the specific tag. Assumed your GUi is named GUI_forever, and the tag of the text box is tag_text_box, so:
handle_text_box = findobj(GUI_forever, 'Tag', 'tag_text_box');
Then, each time you want, you affect a new string to the text box calling the next command line in your code. If for example you want to display the variable named variable_to_display :
set(handle_text_box, 'String', variable_to_display)
Be careful, variable_to_display is a string you write yourself. Don't put the variable itself in the set function or you will have an error. If you want to recover the name of your variable, you can looking this site: Recover variable name
Tania
Tania 2015년 8월 26일
Thank you for your suggestion. I will try that.

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

답변 (1개)

Joseph Cheng
Joseph Cheng 2015년 8월 26일
you can try something like this:
function matlabanswersexample()
figure
hstring = uicontrol('style','text','unit','normal','position',[.4 .65 .2 .1],'string','time:')
hbutton = uicontrol('style','pushbutton','unit','normal','position',[.4 .4 .2 .2],'string','Process',...
'callback',{@buttoncallback,hstring})
function buttoncallback(hobject,event,hstring)
tic
set(hstring,'string','processing')
dots='.';
for i=1:2*randi(10)
processingtext = ['processing' repmat(dots,1,mod(i,5))];
set(hstring,'string',processingtext)
pause(.5)
end
set(hstring,'string',['total processing time: ' num2str(toc)])
it is a quick example i threw together. if you are using GUIDE instead of programming the GUI you would substitute the last line with the text string with the correct handles.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by