Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Using axes within a GUI

Subject: Using axes within a GUI

From: Jane

Date: 1 Nov, 2009 07:35:03

Message: 1 of 4

Hi

I'm trying to create my first GUI WITHOUT using GUIDE. The GUI has several textboxes and pushbuttons, which all work fine. But I can't get an axes to show on the GUI. I'm using the following code, I've included my full code for completness.

function h = testGUI

% Define name and position variables --------------------------------------
vNames = {'nRamp'; 'pRamp'; 'xStep'; 'minY'; 'maxY'; 'attAmp';...
    'attHMHW'; 'attX0'};
vPosText = [10 420 100 20
    10 390 100 20
    10 360 100 20
    10 330 100 20
    10 300 100 20
    10 270 100 20
    10 240 100 20
    10 210 100 20];
vPosEdit = [110 420 100 20
    110 390 100 20
    110 360 100 20
    110 330 100 20
    110 300 100 20
    110 270 100 20
    110 240 100 20
    110 210 100 20];
defaultVals = [4;2048;0.3;100;150;4;5;250];
% ==================================================

% Define GUI --------------------------------------------------------------
h.fig = figure('Position',[250 200 800 450],...
    'Color',[0.8 0.8 0.8]...
    ); %, 'MenuBar', 'None');
% ==================================================

% Add text and edit boxes -------------------------------------------------
for c = 1:length(vNames)
    h.([vNames{c},'Text']) = uicontrol('Style', 'text',...
    'Position', vPosText(c,:),...
    'String',vNames{c},...
    'HorizontalAlignment','Left',...
    'BackgroundColor',[0.8 0.8 0.8]...
    );
    
    h.([vNames{c},'Edit']) = uicontrol('Style','edit',...
    'Position',vPosEdit(c,:),...
    'HorizontalAlignment','Left',...
    'BackgroundColor',[1 1 1],...
    'String',defaultVals(c)...
    );
end
% ==================================================

% Add axes ----------------------------------------------------------------
h.dataPanel = uipanel('Parent',h.fig,...
    'Position',[220 420 250 250]...
    );

h.dataFig = axes('Parent',h.dataPanel...
    );

axes(h.dataFig)
% figure
ezplot('y=x^2+5');
% ==================================================

% Add Pushbutton ----------------------------------------------------------
h.loadButton = uicontrol('Style','pushButton',...
    'Position',[60 170 100 30],...
    'String','Load Data');

set(h.loadButton,'callback',{@loadData,h,vNames});
% ==================================================
%%%%%%%%%%%% END simulateData %%%%%%%%%%%%%%%%%%

function h = loadData(hObject,eventdata,h,vNames)
vals = nan(length(vNames),1);
for c = 1:length(vNames)
    vals(c) = str2double(get(h.([vNames{c},'Edit']),'String'));
end
sum(vals)
    

I've tried several variations on this code, but just can't get it to show. I could really use some help asap.

Many thanks

Subject: Using axes within a GUI

From: ImageAnalyst

Date: 1 Nov, 2009 16:39:32

Message: 2 of 4

I use GUIDE so I can't help you other than to refer you to Matt Fig's
tutorials:
http://www.mathworks.com/matlabcentral/fileexchange/24861-35-complete-gui-examples

Maybe you can set the "Position" property of your axes to make sure
that it fits in the space you've set up for the panel. Perhaps the
default settings make it too big or maybe have some part of the axes
outside of your panel so it doesn't draw it. Why are you putting the
axes insdie of a panel anyway? Are you trying to hide it or show the
axes instantly (this is one reason why you'd do it)?

Subject: Using axes within a GUI

From: Herve

Date: 2 Nov, 2009 07:34:08

Message: 3 of 4

You can't see your axes because the default Units for uipanel is normalized.
Normalized units map the lower-left corner of the panel or figure window to (0,0) and the upper-right corner to (1.0,1.0).

So, you need to change the Units or the Position property of your uipanel.

h.dataPanel = uipanel('Parent',h.fig,...
    'Position',[0.3 0.1 0.6 0.8]...
    );

Subject: Using axes within a GUI

From: Jane

Date: 2 Nov, 2009 16:56:02

Message: 4 of 4

Thanks for your help. I managed to get it working by changing the units to pixels.

I also realised that I was trying to give the position as a map between the bottom left hand corner of the figure window and the top lefthand corner of the panel - where it should have been the bottom left hand corner of the panel.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us