Plotting a floating figure in an axes in GUIDE

4 ビュー (過去 30 日間)
Isra Haroun
Isra Haroun 2018 年 8 月 16 日
回答済み: Rishi Binda 2018 年 8 月 27 日
I would like to diplay the current time in my GUI in Matlab, I would like to use the tutorial (GUI_17) in this file exchange link to produce the watch (or something similar).
I created my own GUI using GUIDE and created an empty axes1, which I wanted to to use as a replacement to the figure definition in the original clock function. I copied the whole function from the link and added it to the bottom of my GUIDE program. This is my attempt to replace the figure handle of the function:
% S.fh = figure('units','pixels',...
% 'position',[300 300 180 50],...
% 'menubar','none',...
% 'name','GUI_17',...
% 'numbertitle','off',...
% 'resize','off');
by the following:
S.fh=handles.axes1;
But it doesn't show any output in the frame, what is the right way to do it?
Thanks
  6 件のコメント
Isra Haroun
Isra Haroun 2018 年 8 月 16 日
編集済み: Isra Haroun 2018 年 8 月 16 日
I tried adding a panel and printing the time to the panel using the following commands instead of the commented parts, still no output.
% S.fh = figure('units','pixels',...
% 'position',[300 300 180 50],...
% 'menubar','none',...
% 'name','GUI_17',...
% 'numbertitle','off',...
% 'resize','off');
S.fh=handles.uipanel1;
% S.tx = uipanel('style','text',...
% 'unit','pix',...
% 'position',[36,169,265,112],...
% 'string',datestr(now,16),...
% 'backgroundc',get(S.fh,'color'),...
% 'fontsize',18,...
% 'fontweight','bold',...
% 'foregroundcolor',[.9 .1 .1]);
drawnow;
S.tx=set(S.fh,'string',datestr(now,16));
Adam
Adam 2018 年 8 月 16 日
You should try stepping through the code to understand what each bit is doing - then you will be able to adapt the code to your needs so much more easily.
S.tx is supposed to be a uicontrol, not a uipanel. You want a uipanel as you have for S.fh, but not in place of the uicontrol that is S.tx.
A uipanel does not have a 'String' property.

サインインしてコメントする。

回答 (1 件)

Rishi Binda
Rishi Binda 2018 年 8 月 27 日
You can refer to this link to know more about creating uipanels and their properties.It has an example of a push button uicontrol with the uipanel as parent.
Create a uipanel S.fh with the required positions. You would need a uicontrol to display the time as a string.
Create a uicontrol S.tx with its Parent property set as S.fh.
S.tx = uicontrol('Parent',S.fh,'style','text',...
You can position the uicontrol according to the uipanel. Now you can set the string property of this uipanel to get the current time.

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by