How to show total execution time using MATLAB GUI

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

Hi. What do you want to know exactly? Because your text box is created with the first opening of the GUI and after you can modify the string displayed on it.
I have used a pushbutton to process my image. It takes a while to complete the total task. I can see total processing time on matlab command window but instead of showing it to a command window I want to show that using GUI (for example static textbox where we can see what variable we have used for processing).
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
Thank you for your suggestion. I will try that.

Sign in to comment.

Answers (1)

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.

Categories

Asked:

on 26 Aug 2015

Answered:

on 26 Aug 2015

Community Treasure Hunt

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

Start Hunting!