How to show total execution time using MATLAB GUI

6 次查看(过去 30 天)
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

请先登录,再进行评论。

回答(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 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by