Azzera filtri
Azzera filtri

Why is my GUI program producing an error when I 'Run' it?

55 visualizzazioni (ultimi 30 giorni)
When I run the below .m file, it gives me the following error:
Error using feval
Undefined function 'frequency_axes_CreateFcn' for input arguments of type 'matlab.graphics.axis.Axes'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in TestInterface (line 43)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)TestInterface('frequency_axes_CreateFcn',hObject,eventdata,guidata(hObject))
Any idea why? Here's the code from my .m:
function varargout = TestInterface(varargin)
% TESTINTERFACE Application M-file for TestInterface.fig
% TESTINTERFACE, by itself, creates a new TESTINTERFACE or raises the existing
% singleton*.
%
% H = TESTINTERFACE returns the handle to a new TESTINTERFACE or the handle to
% the existing singleton*.
%
% TESTINTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTINTERFACE.M with the given input arguments.
%
% TESTINTERFACE('Property','Value',...) creates a new TESTINTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before two_axes_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TestInterface_OpeningFcn via varargin.
%
% *See GUI Options - GUI allows only one instance to run (singleton).
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help TestInterface
% Copyright 2001-2006 The MathWorks, Inc.
% Last Modified by GUIDE v2.5 31-May-2015 00:38:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TestInterface_OpeningFcn, ...
'gui_OutputFcn', @TestInterface_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 TestInterface is made visible.
function TestInterface_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 TestInterface (see VARARGIN)
% Choose default command line output for TestInterface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TestInterface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = TestInterface_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;
% --------------------------------------------------------------------
function plot_button_Callback(hObject, eventdata, handles, varargin)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(0,'DefaultFigureColor','White',...
'defaultaxesfontsize',8,...
'DefaultAxesFontname','Calibri',...
'DefaultTextFontName','Calibri')
x = [0:20];
y = [0:20];
% Get user input from GUI
f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
constant = str2double(get(handles.constant,'String'));
% Calculate data
TestFormula = @(x,y)(x + y.*constant);
[X,Y] = meshgrid(x,y);
Z1 = TestFormula(X,Y);
Z2 = TestFormula(f1,f2);
% Create frequency plot in proper axes
%plot(handles.frequency_axes,f,m(1:257))
s1 = surf(X,Y,Z1)
set(handles.edit5,'String',Z2)
xlabel('X', 'fontweight', 'bold')
ylabel('Y', 'fontweight', 'bold')
%title('(A)', 'FontSize', 12, 'fontweight', 'bold')
view (135,15);
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[0.85,0.6,1],'Rotation',-10.9)
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1,1],'Rotation',11.1)
zlabel('Z', 'fontweight', 'bold')
zh = get(gca,'ZLabel'); % Handle of the z label
set(zh, 'Units', 'Normalized')
pos = get(zh, 'Position');
set(zh, 'Position',pos.*[1.5,1,0],'Rotation',90)
%set(handles.frequency_axes,'XMinorTick','on')
axis tight
camlight
lighting phong
shading interp
set(s1,'FaceColor',[0 0.63 0.91], 'edgecolor',[0 0 0.4],'meshstyle','both','linewidth',.15);
grid on
function f1_input_Callback(hObject, eventdata, handles)
% hObject handle to f1_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f1 field converts to a real number
f1 = str2double(get(hObject,'String'));
if isnan(f1) || ~isreal(f1)
% isdouble returns NaN for non-numbers and f1 cannot be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f1')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
function f2_input_Callback(hObject, eventdata, handles)
% hObject handle to f2_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f2 field converts to a real number
f2 = str2double(get(hObject,'String'));
if isnan(f2) ... % isdouble returns NaN for non-numbers
|| ~isreal(f2) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f2')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function constant_Callback(hObject, eventdata, handles)
% hObject handle to constant (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of constant as text
% str2double(get(hObject,'String')) returns contents of constant as a double
constant = str2double(get(hObject,'String'));
if isnan(constant) ... % isdouble returns NaN for non-numbers
|| ~isreal(constant) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot constant')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
% --- Executes during object creation, after setting all properties.
function constant_CreateFcn(hObject, eventdata, handles)
% hObject handle to constant (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
  4 Commenti

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Mag 2015
You probably copied a GUIDE-created .fig and edited it, instead of opening the interface in GUIDE and telling GUIDE to save it under a new name. Or perhaps you deleted an axes named frequency_axes without going through GUIDE to do so.
Are you launching the interface by double-clicking on the .fig or by commanding
TestInterface
on the command line? Double-clicking would invoke a callback saved with the .fig and it is that callback,
@(hObject,eventdata)TestInterface( 'frequency_axes_CreateFcn', hObject,eventdata,guidata(hObject))
that is causing the problem.
The quick fix is adding a function to your file,
function frequency_axes_Createfcn(varargin)
that does nothing.
The longer term fix is to use the figure browser to find that callback and delete it. Or you can use findobj() or findall() to retrieve the figure properties, look at the callback functions, find the errant one and overwrite it, and re-save the .fig.
  16 Commenti
Lee Yi Zhan
Lee Yi Zhan il 19 Giu 2021
Need Help!!
Unrecognized function or variable 'textDistance_CreateFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Distance1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Distance1('textDistance_CreateFcn',hObject,eventdata,guidata(hObject))
>>
Lee Yi Zhan
Lee Yi Zhan il 19 Giu 2021
Here is my full code
function varargout = Distance1(varargin)
% DISTANCE1 MATLAB code for Distance1.fig
% DISTANCE1, by itself, creates a new DISTANCE1 or raises the existing
% singleton*.
%
% H = DISTANCE1T returns the handle to a new DISTANCE1 or the handle to
% the existing singleton*.
%
% DISTANCE1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DISTANCE1.M with the given input arguments.
%
% DISTANCE1('Property','Value',...) creates a new DISTANCE1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Distance1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Distance1_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 Distance1
% Last Modified by GUIDE v2.5 26-Mar-2017 20:02:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Distance1_OpeningFcn, ...
'gui_OutputFcn', @Distance1_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 DistanceMeasurement is made visible.
function Distance1_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 DistanceMeasurement (see VARARGIN)
% Choose default command line output for DistanceMeasurement
handles.output = hObject;
% Delete any opened ports in MATLAB
delete(instrfind)
% Create a Serial Object
handles.ser = serial('COM3', 'BaudRate',115200,'Terminator','LF',...
'Timeout',10);
% Associate Serial Event, whenever Terminal Character is recived
handles.ser.BytesAvailableFcn = {@SerialEvent, hObject};
% Open Serial Port
fopen(handles.ser);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DistanceMeasurement wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Distance1_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;
function SerialEvent(sObject, eventdata, hGui)
% get the updated handle
handles = guidata(hGui);
% get data from serial port
tmp_c = fscanf(sObject);
set(handles.textDistance, 'String', tmp_c)
% Updates handle structure
guidata(hGui, handles)
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fclose(handles.ser);
delete(handles.ser);
% Hint: delete(hObject) closes the figure
delete(hObject);

Accedi per commentare.

Più risposte (17)

sai kumar
sai kumar il 24 Ott 2017
Modificato: Walter Roberson il 26 Nov 2017
can you please help me rectify this, i guess it is similar to the above question??
Undefined function or variable 'dmessage_CreateFcn'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in trial (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)trial('dmessage_CreateFcn',hObject,eventdata,guidata(hObject))
  10 Commenti
Merveil Patient Noumbi Noumbi
Please help me
Undefined function or variable ‘gui_state’.
Error in GUI_facedetection (line 42) gui_mainfcn(gui_state, varargin {:});
Image Analyst
Image Analyst il 22 Apr 2022
@Merveil Patient Noumbi Noumbi Start your own question (not here), and attach your .fig file and .m file.

Accedi per commentare.


Johana Galarza
Johana Galarza il 26 Nov 2017
Modificato: Walter Roberson il 26 Nov 2017
can you please help me rectify this, i guess it is similar to the above question??
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Campos (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Campos('Calcular_Callback',hObject,eventdata,guidata(hObject))
  3 Commenti

Accedi per commentare.


Amelia van Leeuwen
Amelia van Leeuwen il 7 Feb 2018
Modificato: Walter Roberson il 2 Apr 2018
Hi, I'm having similar issues! Here is my error message:
Undefined function or variable 'm2c_ratio_to_be_tested_KeyPressFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUIWITP (line 65)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUIWITP('m2c_ratio_to_be_tested_KeyPressFcn',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl KeyPressFcn.
Undefined function or variable 'm2c_ratio_to_be_tested_KeyPressFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUIWITP (line 65)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUIWITP('m2c_ratio_to_be_tested_KeyPressFcn',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl KeyPressFcn.
  4 Commenti
Rungkiat Phatthanatapong
Rungkiat Phatthanatapong il 2 Apr 2018
Modificato: Walter Roberson il 2 Apr 2018
Can you help me fix this problem ?
I am using ARTE
Error in drawrobot3d (line 173)
pieza_dibujar = robot.piece{i};
Error in teach>pushbutton_refresh_Callback (line 2911)
drawrobot3d(robot, robot.q)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in teach (line 68)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)teach('pushbutton_refresh_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson il 2 Apr 2018
This appears to relate to http://arvc.umh.es/arte/index_en.html
We need a more complete error message, everything in red, and an outline of what you were doing at the time.

Accedi per commentare.


mohamed mohsen
mohamed mohsen il 30 Mag 2018
Modificato: Walter Roberson il 30 Mag 2018
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in videodct (line 45)
gui_mainfcn(gui_State, varargin{:});
Error while evaluating UIControl Callback.
  6 Commenti
mohamed mohsen
mohamed mohsen il 30 Mag 2018
after I add the code it worked but I had another problem
HL1=hufflen(Hi1);HL2=hufflen(Hi2);
Interrupt while evaluating DestroyedObject Callback.
Walter Roberson
Walter Roberson il 30 Mag 2018
That code does not appear to exist in what you posted.

Accedi per commentare.


satuk Uckus
satuk Uckus il 2 Giu 2018
Modificato: Walter Roberson il 31 Dic 2018
I'm taking this error. how ı can fix it?
Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error due to multiple causes.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in GUI_MECWHEEL (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI_MECWHEEL('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Caused by: Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant4' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant4' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Not enough input arguments. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant5' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant5' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'b'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant7' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant7' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'r'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Integrator1' for parameter 'InitialCondition'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'InitialCondition' in 'WMR_Project_sim_2013GUI/Integrator1' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'Xs'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Integrator5' for parameter 'InitialCondition'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'InitialCondition' in 'WMR_Project_sim_2013GUI/Integrator5' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'th_in'.
Error while evaluating UIControl Callback
  2 Commenti
Walter Roberson
Walter Roberson il 2 Giu 2018
Do you have pushbutton1_Callback invoking sim()? If you are, then you are invoking a Simulink model that relies on some values being present in the workspace of the function that calls sim(). Those might be defined as parameters or there might be From Workspace blocks.
Walter Roberson
Walter Roberson il 2 Giu 2018
The simulation needs
b
r
th_in
Xs
Your code does not define anything like b. Your code defines R with a capital R, but not lower-case r. Your code does not define anything like th_in. Your code defines Sx but not Xs
At the moment, I am not certain what is going on for WMR_Project_sim_2013GUI/Constant4 -- perhaps you left the definition of the constant empty in Simulink ?

Accedi per commentare.


jony shill
jony shill il 31 Dic 2018
function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_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 gui
% Last Modified by GUIDE v2.5 27-Dec-2018 10:52:34
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_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 gui is made visible.
function gui_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 gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_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 Load_Image.
function Load_Image_Callback(hObject, eventdata, handles)
% hObject handle to Load_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im im2
[path, user_cancel] = imgetfile();
if user_cancel
msgbox(sprintf('Invalid Selection'),'Error','Error');
return
end
im = imread(path);
im = im2double(im);
im2 = im;
axes(handle.axes1);
imshow(im);
title('\fontsize(18)\color[rgb]{0.635 0.078 0.184} Patient''s Tooth')
% --- Executes on button press in Detected.
function Detected_Callback(hObject, eventdata, handles)
% hObject handle to Detected (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
axes(handle.axes2);
wd=256;
Input=imresize(a,[256 256]);
figure(1),subplot(1,3,1),imshow(Input);
[r c p] = size(Input);
if p==3
Input= Input(:,:,2);
figure(1),subplot(1,3,2),imshow(Input);
Input = imadjust(Input,[0.4 0.8],[]);
figure(1),subplot(1,3,3),imshow(Input);
end
Input =double(Input);
Length = (r*c);
Dataset = reshape(Input,[Length,1]);
Clusters=5; %k CLUSTERS
Cluster1=zeros(Length,1);
Cluster2=zeros(Length,1);
Cluster3=zeros(Length,1);
Cluster4=zeros(Length,1);
Cluster5=zeros(Length,1);
miniv = min(min(Input));
maxiv = max(max(Input));
range = maxiv - miniv;
stepv = range/Clusters;
incrval = stepv;
for i = 1:Clusters
K(i).centroid = incrval;
incrval = incrval + stepv;
end
update1=0;
update2=0;
update3=0;
update4=0;
update5=0;
mean1=2;
mean2=2;
mean3=2;
mean4=2;
mean5=2;
while ((mean1 ~= update1) & (mean2 ~= update2) & (mean3 ~= update3) & (mean4 ~= update4) & (mean5 ~= update5))
mean1=K(1).centroid;
mean2=K(2).centroid;
mean3=K(3).centroid;
mean4=K(4).centroid;
mean5=K(5).centroid;
for i=1:Length
for j = 1:Clusters
temp= Dataset(i);
difference(j) = abs(temp-K(j).centroid);
end
[y,ind]=min(difference);
if ind==1
Cluster1(i) =temp;
end
if ind==2
Cluster2(i) =temp;
end
if ind==3
Cluster3(i) =temp;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%UPDATE CENTROIDS
cout1=0;
cout2=0;
cout3=0;
cout4=0;
cout5=0;
for i=1:Length
Load1=Cluster1(i);
Load2=Cluster2(i);
Load3=Cluster3(i);
Load4=Cluster4(i);
Load5=Cluster5(i);
if Load1 ~= 0
cout1=cout1+1;
end
if Load2 ~= 0
cout2=cout2+1;
end
%
if Load3 ~= 0
cout3=cout3+1;
end
if Load4 ~= 0
cout4=cout4+1;
end
if Load5 ~= 0
cout5=cout5+1;
end
end
Mean_Cluster(1)=sum(Cluster1)/cout1;
Mean_Cluster(2)=sum(Cluster2)/cout2;
Mean_Cluster(3)=sum(Cluster3)/cout3;
Mean_Cluster(4)=sum(Cluster4)/cout4;
Mean_Cluster(5)=sum(Cluster5)/cout5;
%reload
for i = 1:Clusters
K(i).centroid = Mean_Cluster(i);
end
update1=K(1).centroid;
update2=K(2).centroid;
update3=K(3).centroid;
update4=K(4).centroid;
update5=K(5).centroid;
end
AA1=reshape(Cluster1,[wd wd]);
AA2=reshape(Cluster2,[wd wd]);
AA3=reshape(Cluster3,[wd wd]);
AA4=reshape(Cluster4,[wd wd]);
AA5=reshape(Cluster5,[wd wd]);
figure(3),subplot(2,3,1),imshow(AA1);
subplot(2,3,2),imshow(AA2);
subplot(2,3,3),imshow(AA3);
subplot(2,3,4),imshow(AA4);
subplot(2,3,5),imshow(AA5);
a=AA5;
figure(4),subplot(1,3,1),imshow(a);
a1=im2bw(a);
subplot(1,3,2),imshow(a1);
hold on
mask = false(size(a1));
mask(50:150,40:20) = true;
visboundaries(mask,'Color','b');
bw2 = activecontour(a1, mask, 200, 'edge');
visboundaries(bw2,'Color','r');
title('Initial contour (blue) and final contour (red)');
Trial License -- for use to evaluate programs for possible purchase as an end-user only.
>> gui
The class handle has no Constant property or Static method named 'axes1'.
Error in gui>Load_Image_Callback (line 92)
axes(handle.axes1);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui('Load_Image_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  6 Commenti
Walter Roberson
Walter Roberson il 25 Apr 2019
That code does not contain a guidata call.
You need to replace the first ~ of the function definition of that callback with hObject
HEMANGI NALE
HEMANGI NALE il 29 Apr 2019
thank you so much. now my code is working.

Accedi per commentare.


suoh mikoto
suoh mikoto il 28 Apr 2019
I have same problem, help me.
Error using RGB>pushbutton1_Callback (line 84)
Dimensions of matrices being concatenated are not consistent.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RGB (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)RGB('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
  4 Commenti
Walter Roberson
Walter Roberson il 28 Apr 2019
Your cell array for uigetfile has one column in the first row but 2 columns in the other rows.

Accedi per commentare.


Momen Elhassan
Momen Elhassan il 2 Dic 2019
Modificato: Momen Elhassan il 2 Dic 2019
I have the same problem and only thing I've learned after browsing for so long is that the cause is the same in most cases, but no singular solution as far as I can tell. I've been searching the web for days trying to fix it to no avail.
The 'myecg' variable is an imported one that I had ready. I tried renaming it but that didn't work either.
Undefined function or variable 'myecg'.
Error in CEN320Project>pushbutton1_Callback (line 81)
y=myecg;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CEN320Project (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CEN320Project('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  12 Commenti
Rik
Rik il 5 Ott 2022
We are helping you. Ask a separate question after reading what Image Analyst linked you. You should also consider doing the Onramp tutorial, which is offered for free by Mathworks.
Walter Roberson
Walter Roberson il 5 Ott 2022
using clear all in the middle of the program is like yanking out the chair you are standing on... together with the floor the chair is on, and the building that the floor is in, and the hill that the building is on, and the planet that the hill is on... and the sun that the planet orbits, and the local cluster that the sun is part of... and the galaxy that the local cluster is part of... and then hoping that the residual vacuum energy will still hold you up.

Accedi per commentare.


keith marcenaro
keith marcenaro il 9 Dic 2019
Modificato: keith marcenaro il 9 Dic 2019
When I run the below .m file, it gives me the following error: helpme
Error using +
Matrix dimensions must agree.
Error in programacion1>pushbutton13_Callback (line 698)
segaltpiedesconoc=cotaaltpiedesconoc+presionaltpiedesconoc;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in programacion1 (line 47)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)programacion1('pushbutton13_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  2 Commenti
Walter Roberson
Walter Roberson il 9 Dic 2019
The .m file was not attached. Also it looks like we would need the .fig as well to execute the program.
Walter Roberson
Walter Roberson il 9 Dic 2019
Also you should be creating a new Question for this.

Accedi per commentare.


Ganesh Pakanati
Ganesh Pakanati il 7 Gen 2020
  1 Commento
Walter Roberson
Walter Roberson il 7 Gen 2020
Either you do not have the Image Processing Toolbox installed (or licensed), or else you are using a MATLAB release before R2016a. I suspect you are using a MATLAB too old for imoverlay()

Accedi per commentare.


Iuliana Vlad
Iuliana Vlad il 10 Mag 2020
Same Error.
Error in VladIuliana>calculeaza_Callback (line 876) [V1,m1,J1]=Ans2(((a3/2)/1000),(b2/1000),c2,0);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in VladIuliana (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)VladIuliana('calculeaza_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.

arvin
arvin il 15 Ago 2020
Error using imread (line 349)
File "./sample/1.tiff" does not exist.
Error in CreateDatabase (line 20)
I = (imread(strcat('./sample/',TrainFiles(i).name)));
Error in MAIN_GUI_EMOTION>pushbutton2_Callback (line 143)
CreateDatabase(TrainDatabasePath);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in MAIN_GUI_EMOTION (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)MAIN_GUI_EMOTION('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
  1 Commento
Walter Roberson
Walter Roberson il 16 Ago 2020
You are not cd'd to the directory that has a sample subdirectory inside it. Do not cd to the sample directory itself, cd to the directory that contains the sample directory.

Accedi per commentare.


BHOSALE MOHAN  VILASRAO
BHOSALE MOHAN VILASRAO il 3 Set 2020
Modificato: BHOSALE MOHAN VILASRAO il 3 Set 2020
please help I am facing same kind of error:
Index exceeds matrix dimensions.
Error in RRR_Robot>btn_Forward_Callback (line 167)
handles.Pos_X.String = num2str(floor(T(1,4)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RRR_Robot (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)RRR_Robot('btn_Forward_Callback',hObject,eventdata,guidata(hObject))
167 handles.Pos_X.String = num2str(floor(T(1,4)));
java.lang.ClassCastException: [D cannot be cast to [Ljava.lang.Object;
at com.mathworks.toolbox.matlab.guide.LayoutArea.duplicateComplete(LayoutArea.java:960)
at com.mathworks.toolbox.matlab.guide.LayoutArea$DuplicateObserver.completed(LayoutArea.java:944)
at com.mathworks.toolbox.matlab.guide.utils.LayoutWorker.runOnMatlabThread(LayoutWorker.java:55)
at com.mathworks.jmi.MatlabWorker$2.run(MatlabWorker.java:79)
at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:475)
K>> dbstop if error
and my code :
function varargout = RRR_Robot(varargin)
% RRR_ROBOT MATLAB code for RRR_Robot.fig
% RRR_ROBOT, by itself, creates a new RRR_ROBOT or raises the existing
% singleton*.
%
% H = RRR_ROBOT returns the handle to a new RRR_ROBOT or the handle to
% the existing singleton*.
%
% RRR_ROBOT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RRR_ROBOT.M with the given input arguments.
%
% RRR_ROBOT('Property','Value',...) creates a new RRR_ROBOT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before RRR_Robot_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to RRR_Robot_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 RRR_Robot
% Last Modified by GUIDE v2.5 03-Sep-2020 17:09:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RRR_Robot_OpeningFcn, ...
'gui_OutputFcn', @RRR_Robot_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 RRR_Robot is made visible.
function RRR_Robot_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 RRR_Robot (see VARARGIN)
% Choose default command line output for RRR_Robot
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RRR_Robot wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RRR_Robot_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;
function Theta_1_Callback(hObject, eventdata, handles)
% hObject handle to Theta_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta_1 as text
% str2double(get(hObject,'String')) returns contents of Theta_1 as a double
% --- Executes during object creation, after setting all properties.
function Theta_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Theta_2_Callback(hObject, eventdata, handles)
% hObject handle to Theta_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta_2 as text
% str2double(get(hObject,'String')) returns contents of Theta_2 as a double
% --- Executes during object creation, after setting all properties.
function Theta_2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Theta_3_Callback(hObject, eventdata, handles)
% hObject handle to Theta_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta_3 as text
% str2double(get(hObject,'String')) returns contents of Theta_3 as a double
% --- Executes during object creation, after setting all properties.
function Theta_3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in btn_Forward.
function btn_Forward_Callback(hObject, eventdata, handles)
% hObject handle to btn_Forward (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Th_1 = str2double(handles.Theta_1.String)*pi/180;
Th_2 = str2double(handles.Theta_2.String)*pi/180;
Th_3 = str2double(handles.Theta_3.String)*pi/180;
L_1 = 20;
L_2 = 50;
L_3 = 40;
L(1) = Link([0 L_1 0 pi/2]);
L(2) = Link([0 0 L_2 0]);
L(3) = Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name = 'RRR_Robot';
Robot.plot([Th_1 Th_2 Th_3]);
T = Robot.fkine([Th_1 Th_2 Th_3]);
handles.Pos_X.String = num2str(floor(T(1,4)));
handles.Pos_Y.String = num2str(floor(T(2,4)));
handles.Pos_Z.String = num2str(floor(T(3,4)));
function Pos_X_Callback(hObject, eventdata, handles)
% hObject handle to Pos_X (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_X as text
% str2double(get(hObject,'String')) returns contents of Pos_X as a double
% --- Executes during object creation, after setting all properties.
function Pos_X_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_X (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pos_Y_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_Y as text
% str2double(get(hObject,'String')) returns contents of Pos_Y as a double
% --- Executes during object creation, after setting all properties.
function Pos_Y_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pos_Z_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Z (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_Z as text
% str2double(get(hObject,'String')) returns contents of Pos_Z as a double
% --- Executes during object creation, after setting all properties.
function Pos_Z_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Z (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in btn_Inverse.
function btn_Inverse_Callback(hObject, eventdata, handles)
% hObject handle to btn_Inverse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PX = str2double(handles.Pos_X.String);
PY = str2double(handles.Pos_Y.String);
PZ = str2double(handles.Pos_Z.String);
L_1 = 20;
L_2 = 50;
L_3 = 40;
L(1) = Link([0 L_1 0 pi/2]);
L(2) = Link([0 0 L_2 0]);
L(3) = Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name = 'RRR_Robot';
T = [ 1 0 0 PX;
0 1 0 PY;
0 0 1 PZ;
0 0 0 1];
J = Robot.ikine(T, [0 0 0], [1 1 1 0 0 0]) * 180/pi;
handles.Theta_1.String = num2str(floor(J(1)));
handles.Theta_2.String = num2str(floor(J(2)));
handles.Theta_3.String = num2str(floor(J(3)));
Robot.plot(J*pi/180);
  3 Commenti
BHOSALE MOHAN  VILASRAO
BHOSALE MOHAN VILASRAO il 4 Set 2020
it is giving error at handles part, the following is the result I got with breakpoint at that function.
28 gui_Singleton = 1;
K>> dbcont
166 T = Robot.fkine([Th_1 Th_2 Th_3]);
K>> dbcont
Index in position 2 exceeds array bounds (must not exceed 1).
Error in RRR_Robot>btn_Forward_Callback (line 167)
handles.Pos_X.String = num2str(floor(T(1,4)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RRR_Robot (line 42)
gui_mainfcn(gui_State, varargin{:});