Problem with axes in GUI

5 次查看(过去 30 天)
Ondrej
Ondrej 2014-1-18
评论: abhishek m 2018-3-16
(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
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
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
Amit 2014-1-19
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
Ondrej 2014-1-19
It works! Thank you so much! :)
abhishek m
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 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by