Problem with axes in GUI
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
(sorry for my English)
I have problem with axes in my GUI. When I ran it for the first time - everything is OK, but for the second time (I want to plot some other data in the same axes) it throws error.
Reference to non-existent field 'axes2'.
Error in gui2>detekce_sweepy_5_progui (line 183) axes(handles.axes2);
My part of code:
handles = guihandles();
axes(handles.axes2);
plot(h);
So I donť know how to fix it... Thanks for advices!
댓글 수: 2
Jan
2014년 1월 18일
We do not see enough code for an educated guess of the underlying problem. Please use the debugger to find out more details.
Ondrej
2014년 1월 19일
Here is part of code (but I'm not sure, if you want to go through whole code, cause that I post only small part..but I think that here is everything you need). I use some other functions, but that doesn't work with "gui", "axes" and "handles" parts...
function varargout = gui2(varargin)
% GUI2 MATLAB code for gui2.fig
% GUI2, by itself, creates a new GUI2 or raises the existing
% singleton*.
%
% H = GUI2 returns the handle to a new GUI2 or the handle to
% the existing singleton*.
%
% GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI2.M with the given input arguments.
%
% GUI2('Property','Value',...) creates a new GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui2_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 gui2
% Last Modified by GUIDE v2.5 13-Jan-2014 13:50:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui2_OpeningFcn, ...
'gui_OutputFcn', @gui2_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 gui2 is made visible.
function gui2_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 gui2 (see VARARGIN)
% Choose default command line output for gui2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui2_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 on button press in load1.
function load1_Callback(hObject, eventdata, handles)
% hObject handle to load1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
global fs
global namereny_signal
[nazev1 path1] = uigetfile({'*.wav'},'File Selector');
full_path1 = strcat(path1, nazev1);
[namereny_signal fs] = audioread(full_path1);
set(handles.text1, 'String', nazev1)
if (a==0)
set(handles.analyze1, 'Enable', 'on')
end
a=0;
function load2_Callback(hObject, eventdata, handles)
% hObject handle to load2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
global mersig
global fs
[nazev2 path2] = uigetfile({'*.wav'},'File Selector');
full_path2 = strcat(path2, nazev2);
[mersig fs] = audioread(full_path2);
set(handles.text2, 'String', nazev2)
if (a==0)
set(handles.analyze1, 'Enable', 'on')
end
a=0;
% --- Executes on button press in analyze1.
function analyze1_Callback(hObject, eventdata, handles)
% hObject handle to analyze1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global namereny_signal
global mersig
if get(handles.f_1, 'Value')==1
f1=str2num(get(handles.f_1t, 'String'));
else
f1=0;
end
if get(handles.f_2, 'Value')==1
f2=str2num(get(handles.f_2t, 'String'));
else
f2=0;
end
if get(handles.f_3, 'Value')==1
f3=str2num(get(handles.f_3t, 'String'));
else
f3=0;
end
if get(handles.f_4, 'Value')==1
f4=str2num(get(handles.f_4t, 'String'));
else
f4=0;
end
if get(handles.f_5, 'Value')==1
f5=str2num(get(handles.f_5t, 'String'));
else
f5=0;
end
if get(handles.f_6, 'Value')==1
f6=str2num(get(handles.f_6t, 'String'));
else
f6=0;
end
if get(handles.f_7, 'Value')==1
f7=str2num(get(handles.f_7t, 'String'));
else
f7=0;
end
switch get(get(handles.uipanel2,'SelectedObject'),'Tag');
case 'button5',
switch get(get(handles.uipanel1,'SelectedObject'),'Tag');
case 'sweep_button', detekce_sweepy_5_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'sum_button', detekce_smessin_5_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'smessin_button', detekce_smessin_5_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'mls_button', detekce_mls_5_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
end
case 'button15',
switch get(get(handles.uipanel1,'SelectedObject'),'Tag');
case 'sweep_button', detekce_sweepy_15_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'sum_button', detekce_smessin_15_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'smessin_button', detekce_smessin_15_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
case 'mls_button', detekce_mls_15_progui (namereny_signal, mersig, f1, f2, f3, f4, f5, f6, f7)
end
end
function [data] = detekce_sweepy_5_progui (v2, v, varargin)
global p;
fs=44100;
ss = zarovnani_signalu2(v,v2); %srovnaný signál
data=zeros(73,nargin-2);
start=6;
i=1;
legenda(1:7)=0;
while i<74
h = sinesweeps_response1(ss(start*fs:(start+2)*fs,1), fs, 100, 0.4);
if i==1
% handles = guihandles();
axes(handles.axes2);
plot(h); title('Zazoomujte v impuslni odezve tak, aby byl videt i první odraz - potvrdte stisknutim Enter.');
zoom on;
waitfor(gcf,'CurrentCharacter',13)
zoom reset
zoom off
title('Kliknete pred prvni odraz.');
[x_coord]=ginput(1);
end
four=abs(fft(h(1:round(x_coord),1),fs));
fr=mag2db(abs(four(2:fs/2)));
axes(handles.axes3);
semilogx(fr)
title('Frekvenční charakteristika před korekcí');
y=1;
for k=1:nargin-2
if varargin{k} ~= 0 %pokud je nezatrhnutá frekvence
data(i,y)=fr(varargin{k});
legenda(y)=varargin{k};
y=y+1;
end
end
i=i+1;
start=start+4;
end
%%korekce fr
load('ir_6010A.mat')
four=abs(fft(ir_6010A,fs));
fr_z=mag2db(abs(four(2:fs/2)));
axes(handles.axes4);
semilogx(fr+fr_z);
title('Frekvenční charakteristika po korekci');
y=1;
for k=1:nargin-2
if varargin{k} ~= 0 %pokud je nezatrhnutá frekvence
data(:,y)=data(:,y)+fr_z(varargin{k});
y=y+1;
end
end
%%vykresleni
teta=[-180 -175 -170 -165 -160 -155 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180];
romin=min(min(data));
romax=max(max(data));
barvy=['k' 'b' 'r' 'm' 'g' 'c' 'y'];
% handles = guihandles();
axes(handles.axes1);
for k=1:(y-1)
p(k)=Dirplot(teta,(data(:,k))','-r',[romax romin 1]);
hold on
set(p(k),'color',barvy(k),'linewidth',2)
end
legg=legend(strcat(num2str(legenda(1)), ' Hz'),strcat(num2str(legenda(2)), ' Hz'),strcat(num2str(legenda(3)), ' Hz'),strcat(num2str(legenda(4)), ' Hz'),strcat(num2str(legenda(5)), ' Hz'),strcat(num2str(legenda(6)), ' Hz'),strcat(num2str(legenda(7)), ' Hz'));
set(legg,'Location','NorthEastOutside')
title('Směrová charakteristika mikrofonu s krokem 5°');
hold off
채택된 답변
Amit
2014년 1월 19일
0 개 추천
You will not get this issue if you remove handles = guihandles();
handles structure is available to all functions. in the section where you are trying this, axes(handles.axes2) will work without calling handles = guihandles().
Try simply
% handles = guihandles()
axes(handles.axes2);
plot(h);
I am not completely sure why axes2 gets removed from the handles structure after you execute the code the way you have done.
댓글 수: 5
Ondrej
2014년 1월 19일
If I remove that, i get another problem.
Undefined variable "handles" or class "handles.axes2".
Amit
2014년 1월 19일
Post the whole GUI code.
try passing handles in the function
function [data] = detekce_sweepy_5_progui(handles, v2, v, varargin)
handles is not defined for the function detekce_sweepy_5_progui, so you need to pass it as a variable.
Which also means, that you have to add 'handles' as the first variable every location you have used this function detekce_sweepy_5_progui
Ondrej
2014년 1월 19일
It works! Thank you so much! :)
abhishek m
2018년 3월 16일
im2=imread('sk.png'); bw = im2; bw = sum((1-im2).^2, 3) > .5; %bw = min( bw, [], 3 ) < 50 ; % dark pixels - intensity lower than 50 [y x] = find( bw ); % note that find returns row-col coordinates.
mx = mean(x); my = mean(y); C = [ mean( (x-mx).^2 ), mean( (x-mx).*(y-my) );... mean( (x-mx).*(y-my) ) mean( (y-my).^2 ) ]; [V D] = eig( C );
quiver( mx([1 1]), my([1 1]), (V(1,:)*D), (V(2,:)*D), .05 ); [~,mxi] = max(diag(D)); % find major axis index: largest eigen-value or = atan2( V(2,mxi), V(1,mxi) ) * 180/pi ; % convert to degrees for readability rotate = imrotate( im2, or-90 );
handles = guihandles();
axes(handles.axes2);
imshow( rotate );
set(handles.text3, 'String',or-180);
i am getting error in axes like "Reference to non-existent field 'axes2'" how to fix it>
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
