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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by