How to show total execution time using MATLAB GUI
7 views (last 30 days)
Show older comments
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 Comments
Mathieu
on 26 Aug 2015
Edited: Mathieu
on 26 Aug 2015
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
Answers (1)
Joseph Cheng
on 26 Aug 2015
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.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!