-2

This is all of the code as of right now. The correct image is displayed when you change the selected button in the button group but no image is displayed until you change the selected button. I want the first image to be FloorPlan{1} as it says in axes1_CreateFcn but it is not working. The axes are simply not there until you change the button.

function varargout = selectfloorplan(varargin)
% SELECTFLOORPLAN MATLAB code for selectfloorplan.fig
%      SELECTFLOORPLAN, by itself, creates a new SELECTFLOORPLAN or raises the existing
%      singleton*.
%
%      H = SELECTFLOORPLAN returns the handle to a new SELECTFLOORPLAN or the handle to
%      the existing singleton*.
%
%      SELECTFLOORPLAN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SELECTFLOORPLAN.M with the given input arguments.
%
%      SELECTFLOORPLAN('Property','Value',...) creates a new SELECTFLOORPLAN or raises     the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before selectfloorplan_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to selectfloorplan_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help selectfloorplan

% Last Modified by GUIDE v2.5 18-Apr-2014 11:16:48

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @selectfloorplan_OpeningFcn, ...
                   'gui_OutputFcn',  @selectfloorplan_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before selectfloorplan is made visible.
function selectfloorplan_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to selectfloorplan (see VARARGIN)

% Choose default command line output for selectfloorplan
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes selectfloorplan wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = selectfloorplan_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
global FloorPlans floorplanselection
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

%Hint: place code in OpeningFcn to populate axes1
imagesc(FloorPlans{1})
floorplanselection=FloorPlans{1};
axis off
axis('image')
colormap(gray)


% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
global FloorPlans floorplanselection
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%   EventName: string 'SelectionChanged' (read only)
%   OldValue: handle of the previously selected object or empty if none was selected
%   NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag')
    case 'rad1'
        axes(handles.axes1)
        imagesc(FloorPlans{1})
        floorplanselection=FloorPlans{1};
        axis off
        axis('image')
        colormap(gray)
    case 'rad2'
        axes(handles.axes1)
        imagesc(FloorPlans{2})
        floorplanselection=FloorPlans{2};
        axis off
        axis('image')
        colormap(gray)
    case 'rad3'
        axes(handles.axes1)
        imagesc(FloorPlans{3})
        floorplanselection=FloorPlans{3};
        axis off
        axis('image')
        colormap(gray)
    case 'rad4'
        axes(handles.axes1)
        imagesc(FloorPlans{4})
        floorplanselection=FloorPlans{4};
        axis off
        axis('image')
        colormap(gray)
    case 'rad5'
        axes(handles.axes1)
        imagesc(FloorPlans{5})
        floorplanselection=FloorPlans{5};
        axis off
        axis('image')
        colormap(gray)
    case 'rad6'
        axes(handles.axes1)
        imagesc(FloorPlans{6})
        floorplanselection=FloorPlans{6};
        axis off
        axis('image')
        colormap(gray)
end


% --- Executes on button press in nectbtn.
function nectbtn_Callback(hObject, eventdata, handles)
% hObject    handle to nectbtn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selectrobot
delete(get(hObject, 'parent'));


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
mainmenu
delete(get(hObject, 'parent'));


% --- Executes during object creation, after setting all properties.
function uipanel1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to uipanel1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
redmoncoreyl
  • 133
  • 9
  • What problem are you having? Explain where you are stuck and what you have tried. This looks a bit like a homework problem as well. – David Apr 17 '14 at 04:33
  • I actually changed something that I thought was the problem. In each case, I made the statement axes(axis1) to be axes(axes1) to fit the tag of the axes. It still doesn't work. I think it has to do with those lines because the creation of the axes work fine. The first error I get in the command window is: Undefined function or variable 'axes1', followed by a long list of other things. – redmoncoreyl Apr 17 '14 at 12:43
  • I tried something that works. In the axes1_createFcn, I defined a global variable h. also in that fcn, h=gcbo. Then in the SelesctionChangeFcn, I defined h as global and changed all of the axes1 to h. It worked perfectly, I just wish there was a way to get the handle directly without a global variable. – redmoncoreyl Apr 17 '14 at 12:54

1 Answers1

0

The ID for your graphics objects are stored in the handles structure that GUIDE stores and passes between callbacks. The reason axis1 doesn't work as an input is because it's not defined in the scope of your callback function so the function has no way to address it. This is why your global workaround 'fixes' the problem.

If you substitute handles.axes1 (or whatever your axes object tag is) for axis1 in your axes() calls, it should perform as you're expecting.

sco1
  • 12,154
  • 5
  • 26
  • 48
  • I just tried that and it works for the Selection change function but when the GUI first runs the axes aren't populated. I didn't get an error. If I change the button, the graph changes but the axes are empty until I change the button. I tried to mess around in the axes1 creation and the button group creation and it hasn't fixed things. – redmoncoreyl Apr 18 '14 at 15:21
  • You're going to have to be more specific. Update your post with your changes and post the full code. – sco1 Apr 18 '14 at 17:21