2014-04-17 1 views
-2

이것은 현재 모든 코드입니다. 단추 그룹에서 선택한 단추를 변경할 때 올바른 이미지가 표시되지만 선택한 단추를 변경할 때까지 이미지가 표시되지 않습니다. 첫 번째 이미지가 axes1_CreateFcn에서 말하는 것처럼 FloorPlan {1}이 되길 원하지만 작동하지 않습니다. 버튼을 변경하기 전까지는 축이 표시되지 않습니다. 그래픽 객체matlab GUIDE의 라디오 버튼을 사용하여 다른 이미지를 어떻게 표시합니까?

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 
+0

어떤 문제가 있습니까? 어디에서 붙어 있고 무엇을 시도했는지 설명하십시오. 이것은 마치 숙제 문제처럼 보입니다. – David

+0

사실 나는 문제라고 생각했던 것을 바 꾸었습니다. 각각의 경우에, 축의 태그에 맞도록 명령문 축 (axis1)을 축 (axes1)으로 만들었습니다. 여전히 작동하지 않습니다. 축이 제대로 작동하기 때문에이 선과 관련이 있다고 생각합니다. 명령 창에서 첫 번째 오류는 다음과 같습니다. 정의되지 않은 함수 또는 변수 'axes1'다음에 긴 목록이옵니다. – redmoncoreyl

+0

나는 작동하는 것을 시도했다. axes1_createFcn에서 전역 변수 h를 정의했습니다. 또한 그 fcn, h = gcbo. 그런 다음 SelesctionChangeFcn에서 h를 전역으로 정의하고 모든 axes1을 h로 변경했습니다. 완벽하게 작동 했으므로 전역 변수없이 직접 핸들을 가져 오는 방법이 있었으면 좋겠습니다. – redmoncoreyl

답변

0

아이디 상점 안내 및 콜백간에 전달 handles 구조에 저장된다. 이유는 axis1이 콜백 함수의 범위에서 정의되지 않았기 때문에 입력으로 작동하지 않습니다. 따라서 함수는이 함수를 처리 할 방법이 없습니다. 이것이 글로벌 해결 방법이 문제를 '고치는'이유입니다.

axes() 호출에서 axis1handles.axes1 (또는 축 객체 태그가 무엇이든)으로 대체하면 예상대로 수행됩니다.

+0

방금 ​​시도했는데 선택 변경 기능에서 작동하지만 GUI를 처음 실행하면 축이 채워지지 않습니다. 나는 실수를하지 않았다. 버튼을 변경하면 그래프가 변경되지만 버튼을 변경할 때까지 축이 비어 있습니다. 나는 축 1 생성과 버튼 그룹 생성에서 주위를 어지럽 혀 지려고했지만 고정되어 있지 않습니다. – redmoncoreyl

+0

당신은 더 구체적이어야 할 것입니다. 게시물을 변경 내용으로 업데이트하고 전체 코드를 게시하십시오. – excaza