Plotting a floating figure in an axes in GUIDE

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 commentaires

Adam
Adam le 16 Août 2018
Modifié(e) : Adam le 16 Août 2018
Please don't paste people's File Exchange code into the forum. I have edited this out and added the link to the relevant code in the File Exchange itself. I'm not entirely sure of the situation with regard to posting other people's code, but it is bad form at the least, as it should be used with the license that comes with it (which allows you to use it freely, but retaining the license text file with it).
Adam
Adam le 16 Août 2018
Modifié(e) : Adam le 16 Août 2018
S.fh was a figure handle in the code you comment out, whereas you are replacing it with an axes handle. You would need to give it your own figure handle there if you want it to be embedded in an existing figure, and would have to edit the 'Position' parameters of the components to fit where you want it to go. UI components such as text boxes cannot be parented on an axes, they need your figure handle.
Isra Haroun
Isra Haroun le 16 Août 2018
Modifié(e) : Isra Haroun le 16 Août 2018
I'm sorry, I added the link to sow the source of the code and confirming their property of it. I've also edited the position to suit my empty axes position in the code. Can I add figure handles in GUIDE?
Adam
Adam le 16 Août 2018
Modifié(e) : Adam le 16 Août 2018
Unless you have changed the tag of the main figure (which I always do) then
handles.figure1
will be the handle to your GUIDE figure. You can double-check this by clocking anywhere on the figure in GUIDE (i.e. on the grey background part, not any of the components) and it will show the tag in the information bar at the bottom (or double click it and look in the Property Inspector for the 'Tag').
Having said all that, you would be better of placing a panel on your figure and using this instead of a figure handle as then you don't have the position it yourself within the figure, only within the panel that you can size and position yourself in GUIDE. The panel's tag can be found in the same way I describe for the figure, but by clicking the panel you create rather than the figure.
Isra Haroun
Isra Haroun le 16 Août 2018
Modifié(e) : Isra Haroun le 16 Août 2018
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 le 16 Août 2018
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.

Connectez-vous pour commenter.

Réponses (1)

Rishi Binda
Rishi Binda le 27 Août 2018
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.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by