MATLAB Answers

Error while evaluating uicontrol Callback (GUI_handle problem)

536 views (last 30 days)
Metin
Metin on 19 Aug 2013
hi everybody, my problem is about programmed GUI. first I read "mean" and "standard deviation" for a vector from GUI and than create a vector depends on those values to show all values to user to make them editable also. Up to now I have succeed to create the the editable table but the values does not look like as user has initialized, I guess it is because of str2double and num2str conversions, because in the function that I want to make the calculation it gives error of
%%%%%%%%%% ??? Reference to non-existent field 'R_leak_1_mean_value'. Error in ==> GUI_Module>Button_Calculate at 150 h.R_leak_1_value =ones(48,1).*h.R_leak_1_mean_value + randn(48,1).*h.R_leak_1_std_value; ??? Error while evaluating uicontrol Callback %%%%%%%%% here infact when I run simulation step by step in the handle of "h" I can see R_leak_1_mean_value which is a conversed value of string of the same variable but whenever I go another function of where I want to create the array it gives this error. Although I use at the first and last line of each
function
" variables =guidata(h.fig);" and "guidata(h.fig,variables);" respectively I think still I cannot save and call the variable whenever I need I hope I have clearly defined the problem I have given the m-file that I've written for GUI any suggestion will appreciated thanks in advance:)
if true function GUI_module h.fig = figure('units','pixel','OuterPosition',[2 3 750 450],'ToolBar','none','MenuBar','none','Name','Balancing Model','NumberTitle','off'); variables =guidata(h.fig); %% Text boxes h.components_text = uicontrol('style','text','units','normalized','position',[1/20 36/40 0.46 1/20], 'HorizontalAlignment','center','string','Initialization'); h.mean_text = uicontrol('style','text','units','normalized','position',[6/20 33/40 0.1 1/20], 'HorizontalAlignment','center','string','Mean value'); h.std_text = uicontrol('style','text','units','normalized','position',[8.15/20 33/40 0.1 1/20],'HorizontalAlignment','center','string','Std value'); h.R_leak_1_text = uicontrol('style','text','units','normalized','position',[1/20 30/40 0.2 1/20], 'HorizontalAlignment','left', 'string','R_leak_1'); h.R_leak_2_text =uicontrol('style','text','units','normalized','position',[1/20 26/40 0.2 1/20], 'HorizontalAlignment','left', 'string','R_leak_2'); h.R_leak_1_mean=uicontrol('style','edit','string','','units','normalized','position', [ 6/20 30/40 0.1 1/20], 'callback',@R_leak_1_mean); h.R_leak_1_std=uicontrol('style','edit','string','','units','normalized','position', [ 8.15/20 30/40 0.1 1/20],'callback',@R_leak_1_std); h.R_leak_2_mean=uicontrol('style','edit','string','','units','normalized','position', [ 6/20 26/40 0.1 1/20], 'callback',@R_leak_2_mean); h.R_leak_2_std = uicontrol('style','edit','string','','units','normalized','position', [ 8.15/20 26/40 0.1 1/20],'callback',@R_leak_2_std); %% Button h.ButtonCalculate = uicontrol('style','pushbutton','string','Calculete values','units','normalized','position', [15/20 2/40 0.15 1/20]); %% Callbacks set(h.R_leak_1_mean,'callback',{@R_leak_1_mean,h}); set(h.R_leak_1_std,'callback',{@R_leak_1_std,h}); set(h.R_leak_2_mean,'callback',{@R_leak_2_mean,h}); set(h.R_leak_2_std,'callback',{@R_leak_2_std,h}); function R_leak_1_mean(hobject,event,h) variables =guidata(h.fig); h=read_inputs(h); guidata(h.fig,variables); end function R_leak_1_std(hobject,event,h) variables =guidata(h.fig); h=read_inputs(h); guidata(h.fig,variables); end function R_leak_2_mean(hobject,event,h) variables =guidata(h.fig); h=read_inputs(h); guidata(h.fig,variables); end function R_leak_2_std(hobject,event,h) variables=guidata(h.fig) h=read_inputs(h); guidata(h.fig,variables); end function [h]=Button_Calculate(hObject,eventdata,h) variables =guidata(h.fig); h.R_leak_1_value =h.R_leak_1_mean_value + randn(48,1).*h.R_leak_1_std_value; h.R_leak_2_value =h.R_leak_2_mean_value + randn(48,1).*h.R_leak_2_std_value; h.fig_2 =figure('units','pixel','OuterPosition',[-3 -3 750 450],'ToolBar','none','MenuBar','none','Name','Circuit Parameters','NumberTitle','off'); edit_table =[true true]; h.table =uitable('units','normalized','position',[2/40 2/40 30/40 34/40],'ColumnWidth','auto','ColumnEditable', edit_table); cnames ={'R_leak_1','R_leak_2'}; rnames ={'Cell_1','Cell_2','Cell_3','Cell_4','Cell_5','Cell_6','Cell_7','Cell_8'}; set(h.R_leak_1,'string',num2str(h.R_leak_1_value)); set(h.R_leak_2,'string',num2str(h.R_leak_2_value)); h.my_data =zeros(8,2); h.my_data(:,1) =h.R_leak_1; h.my_data(:,2) =h.R_leak_2; set(h.table,'Data',h.my_data,'Columnname',cnames, 'Rowname', rnames); h.Button_simulate = uicontrol('style','pushbutton','string','Run simulation','units','normalized','position', [17/20 4/40 0.1 1/20]); set(h.ButtonSimulate,'callback',{@Button_Simulate,h}); guidata(h.fig,variables); end function [h]=Button_Simulate(hObject,eventdata,h) variables =guidata(h.fig); assignin('base','R_leak_1',h.R_leak_1_value); assignin('base','R_leak_2',h.R_leak_2_value); guidata(h.fig,variables); end function [h]=read_inputs(h) variables =guidata(h.fig); h.R_leak_1_mean_value =str2double(get(h.R_leak_1_mean,'String')); h.R_leak_1_std_value =str2double(get(h.R_leak_1_std,'String')); h.R_leak_2_mean_value =str2double(get(h.R_leak_2_mean,'String')); h.R_leak_2_std_value =str2double(get(h.R_leak_2_std,'String')); guidata(h.fig,variables); end end end %%%%%%%%%%%%%%%

  0 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 20 Aug 2013
The code you posted is incomprehensibly formatted.
However, my guess is, that you did a function call, that changes the handle, but didn't update your handles structure after that.
i.e.
function change_handle( hObject, eventdata, handles )
handles.value_A = 5;
guidata( hObject, handles );
function caller_function( hObject, eventdata, handles )
handles = guidata( hObject, handles );
change_handle( hObject, evendata, handles );
% uncomment the following line, to prevent your error
% handles = guidata( hObject );
% if line above is commented, the following will crash
set( handles.text_field, 'String', num2str( handles.value_A ) );
What happens is, that the function change_handles is called in the caller_function and the field handles.value_A is created. The caller_function then wants to access this field. If the handles structure is not updated, the field is simply non-existant in allthough you called guidata() in the change_handles function.

  3 Comments

Metin
Metin on 20 Aug 2013
if true
function GUI_Module
close all
clc
h.fig = figure('units','pixel','OuterPosition',[2 3 750 450],'ToolBar','none','MenuBar','none','Name','Balancing Model','NumberTitle','off');
%%Text boxes
h.components_text = uicontrol('style','text','units','normalized','position',[1/20 36/40 0.46 1/20], 'HorizontalAlignment','center','string','Initialization');
h.mean_text = uicontrol('style','text','units','normalized','position',[6/20 33/40 0.1 1/20], 'HorizontalAlignment','center','string','Mean value');
h.std_text = uicontrol('style','text','units','normalized','position',[8.15/20 33/40 0.1 1/20],'HorizontalAlignment','center','string','Std value');
h.R_leak_1_text = uicontrol('style','text','units','normalized','position',[1/20 30/40 0.2 1/20], 'HorizontalAlignment','left', 'string','R_leak_1');
h.R_leak_2_text = uicontrol('style','text','units','normalized','position',[1/20 26/40 0.2 1/20], 'HorizontalAlignment','left', 'string','R_leak_2');
h.R_inner_text = uicontrol('style','text','units','normalized','position',[1/20 22/40 0.2 1/20], 'HorizontalAlignment','left', 'string','R_inner');
h.Capacitors_text = uicontrol('style','text','units','normalized','position',[1/20 18/40 0.2 1/20], 'HorizontalAlignment','left', 'string','Capacitors');
h.circuit_text = uicontrol('style','text','units','normalized','position',[1/20 14/40 0.2 1/20], 'HorizontalAlignment','left', 'string','Initial capacitor voltage');
h.max_min_text = uicontrol('style','text','units','normalized','position',[1/20 10/40 0.2 1/20], 'HorizontalAlignment','left', 'string','Module voltages (min&max)');
h.simulation_text = uicontrol('style','text','units','normalized','position',[1/20 6/40 0.2 1/20], 'HorizontalAlignment','left', 'string','"step" and "end" times');
h.quant_eta_text = uicontrol('style','text','units','normalized','position',[1/20 2/40 0.2 1/20], 'HorizontalAlignment','left', 'string','"efficiency" and "quantization" ');
%%Editboxes
h.R_leak_1_mean = uicontrol('style','edit','string','','units','normalized','position', [ 6/20 30/40 0.1 1/20], 'callback',@R_leak_1_mean);
h.R_leak_1_std = uicontrol('style','edit','string','','units','normalized','position', [ 8.15/20 30/40 0.1 1/20],'callback',@R_leak_1_std);
h.R_leak_2_mean = uicontrol('style','edit','string','','units','normalized','position', [ 6/20 26/40 0.1 1/20], 'callback',@R_leak_2_mean);
h.R_leak_2_std = uicontrol('style','edit','string','','units','normalized','position', [ 8.15/20 26/40 0.1 1/20],'callback',@R_leak_2_std);
h.R_inner_mean = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 22/40 0.1 1/20], 'callback',@R_inner_mean);
h.R_inner_std = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 22/40 0.1 1/20],'callback',@R_inner_std);
h.Cap_mean = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 18/40 0.1 1/20], 'callback',@Cap_mean);
h.Cap_std = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 18/40 0.1 1/20],'callback',@Cap_std);
h.U_init_mean = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 14/40 0.1 1/20], 'callback',@U_init_mean);
h.U_init_std = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 14/40 0.1 1/20],'callback',@U_init_std);
h.U_max_set = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 10/40 0.1 1/20], 'callback',@U_max_set);
h.U_min_set = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 10/40 0.1 1/20],'callback',@U_min_set);
h.t_step = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 6/40 0.1 1/20], 'callback',@t_step);
h.t_end = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 6/40 0.1 1/20],'callback',@t_end);
h.eta = uicontrol('style','edit','string','','units','normalized','Position', [ 6/20 2/40 0.1 1/20], 'callback',@eta);
h.quant = uicontrol('style','edit','string','','units','normalized','Position', [ 8.15/20 2/40 0.1 1/20],'callback',@quant);
%%Button
h.ButtonCalculate = uicontrol('style','pushbutton','string','Calculete values','units','normalized','position', [15/20 2/40 0.15 1/20]);
%%functions for each edit boxes R_leak_1 calculation
function R_leak_1_mean(hObject,eventdata,h)
variable=guidata(h.fig);
h.R_leak_1_mean_value =str2double(get(h.R_leak_1_mean,'String'));
guidata(h.fig,variable);
end
function R_leak_1_std(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%R_leak_2 calculation
function R_leak_2_mean(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function R_leak_2_std(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%functions for each edit boxes R_inner calculation
function R_inner_mean(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function R_inner_std(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%functions for each edit boxes CAPACITENCE calculation
function Cap_mean(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function Cap_std(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%functions for each edit boxes U_INITIAL calculation
function U_init_mean(varargin)
varargin=guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function U_init_std(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%functions for simulation parameters
function U_max_set(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function U_min_set(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function t_step(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function t_end(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function eta(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
function quant(varargin)
varargin =guidata(h.fig);
h=read_inputs(h);
guidata(h.fig,varargin);
end
%%Fuction of Calculate & edit values Button
function ButtonCalculate(hObject,eventdata,h)
variable =guidata(h.fig);
h.R_leak_1_value =h.R_leak_1_mean_value + randn(48,1).*h.R_leak_1_std_value;
h.R_leak_2_value =h.R_leak_2_mean_value + randn(48,1).*h.R_leak_2_std_value;
h.R_inner_value =h.R_inner_mean_value + h.R_inner_std_value.*randn(48,1);
h.Cap_value =h.Cap_mean_value + randn(48,1).*h.Cap_std_value;
h.U_init_value =h.U_init_mean_value + randn(48,1).*h.U_init_std_value;
h.fig_2 =figure('units','pixel','OuterPosition',[-3 -3 750 450],'ToolBar','none','MenuBar','none','Name','Circuit Parameters','NumberTitle','off');
edit_table =[true true true true true];
h.table =uitable('units','normalized','position',[2/40 2/40 30/40 34/40],'ColumnWidth','auto','ColumnEditable', edit_table);
cnames ={'R_leak_1','R_leak_2','R_inner','Capacitences','U_initial'};
rnames ={'Cell_1','Cell_2','Cell_3','Cell_4','Cell_5','Cell_6','Cell_7','Cell_8','Cell_9','Cell_10','Cell_11','Cell_12','Cell_13','Cell_14','Cell_15','Cell_16','Cell_17','Cell_18','Cell_19','Cell_20','Cell_21','Cell_22','Cell_23','Cell_24','Cell_25','Cell_26','Cell_27','Cell_28','Cell_29','Cell_30','Cell_31','Cell_32','Cell_33','Cell_34','Cell_35','Cell_36','Cell_37','Cell_38','Cell_39','Cell_40','Cell_41','Cell_42','Cell_43','Cell_44','Cell_45','Cell_46','Cell_47','Cell_48'};
set(h.R_leak_1,'string',num2str(h.R_leak_1_value));
set(h.R_leak_2,'string',num2str(h.R_leak_2_value));
set(h.R_inner,'string',num2str(h.R_inner_value));
set(h.Cap,'string',num2str(h.Cap_value));
set(h.U_init,'string',num2str(h.U_init_value));
h.my_data =zeros(48,5);
h.my_data(:,1) =h.R_leak_1;
h.my_data(:,2) =h.R_leak_2;
h.my_data(:,3) =h.R_inner;
h.my_data(:,4) =h.Cap;
h.my_data(:,5) =h.U_init;
set(h.table,'Data',h.my_data,'Columnname',cnames, 'Rowname', rnames);
h.Button_simulate = uicontrol('style','pushbutton','string','Run simulation','units','normalized','position', [17/20 4/40 0.1 1/20]);
set(h.ButtonSimulate,'callback',{@Button_Simulate,h});
guidata(h.fig,variable);
end
%%Run_simulation Button
function [h]=Button_Simulate(varargin)
%varargin =guidata(h.fig);
assignin('base','R_leak_1',h.R_leak_1_value);
assignin('base','R_leak_2',h.R_leak_2_value);
assignin('base','R_inner',h.R_inner_value);
assignin('base','Cap',h.Cap_value);
assignin('base','U_init',h.U_init_value);
assignin('base','U_max_set',h.U_max_set_value);
assignin('base','U_min_set',h.U_min_set_value);
assignin('base','t_step',h.t_step_value);
assignin('base','t_end',h.t_end_value);
assignin('base','eta',h.eta_value);
assignin('base','quant',h.quant_value);
guidata(h.fig,variables);
open('super_capacitor_balance_2008a');
%sim('super_capacitor_balance_2008a');
end
%%Read functions
function [h]=read_inputs(h)
% variables =guidata(h.fig);
h.R_leak_1_mean_value =str2double(get(h.R_leak_1_mean,'String'));
h.R_leak_1_std_value =str2double(get(h.R_leak_1_std,'String'));
h.R_leak_2_mean_value =str2double(get(h.R_leak_2_mean,'String'));
h.R_leak_2_std_value =str2double(get(h.R_leak_2_std,'String'));
h.R_inner_mean_value =str2double(get(h.R_inner_mean,'String'));
h.R_inner_std_value =str2double(get(h.R_inner_std,'String'));
h.Cap_mean_value =str2double(get(h.Cap_mean,'String'));
h.Cap_std_value =str2double(get(h.Cap_std,'String'));
h.U_init_mean_value =str2double(get(h.U_init_mean,'String'));
h.U_init_std_value =str2double(get(h.U_init_std,'String'));
h.U_max_set_value =str2double(get(h.U_max_set,'String'));
h.U_min_set_value =str2double(get(h.U_min_set,'String'));
h.t_step_value =str2double(get(h.t_step,'String'));
h.t_end_value =str2double(get(h.t_end,'String'));
h.eta_value =str2double(get(h.eta,'String'));
h.quant_value =str2double(get(h.quant,'String'));
%guidata(h.fig,variables);
end
%%Callbacks
set(h.R_leak_1_mean,'callback',{@R_leak_1_mean,h});
set(h.R_leak_1_std,'callback',{@R_leak_1_std,h});
set(h.R_leak_2_mean,'callback',{@R_leak_2_mean,h});
set(h.R_leak_2_std,'callback',{@R_leak_2_std,h});
set(h.R_inner_mean,'callback',{@R_inner_mean,h});
set(h.R_inner_std,'callback',{@R_inner_std,h});
set(h.Cap_mean,'callback',{@Cap_mean,h});
set(h.Cap_std,'callback',{@Cap_std,h});
set(h.U_init_mean,'callback',{@U_init_mean,h});
set(h.U_init_std,'callback',{@U_init_std,h});
set(h.U_max_set,'callback',{@U_max_set,h});
set(h.U_min_set,'callback',{@U_min_set,h});
set(h.t_step,'callback',{@t_step,h});
set(h.t_end,'callback',{@t_end,h});
set(h.ButtonCalculate,'callback',{@ButtonCalculate,h});
end
%%%%%%%%%I hope this comprehensive thanks for your answer but I couldn't %%%mange to solve end
Metin
Metin on 20 Aug 2013
Hi Jan, you are right about to define the problem, but normally when I have to use calling variables with
variable=guidata(hObject)
and also to store the variable in the handle
guidata(hObject,variables)
after I write callback function of each edit box, the variable inside has to be saved in the handle up to change or erase edit box but why I couldn't manage to reach the variable when called even I stored it before, uncomment the line that you have mentioned results in other error of:
if true
??? Error while evaluating uicontrol Callback
??? Undefined function or variable 'variable'.
end
so it seems there has to be another way or do I have to change all the program structure? any comment please
thanks
Jan
Jan on 21 Aug 2013
Are you using GUIDE to develop your GUI? If not taking a good look at a GUIDE generated GUI may be a good idea - if only to see how a clean structure can be accomplished.

Sign in to comment.

More Answers (1)

Ahmed Saeed Mansour
Ahmed Saeed Mansour on 10 May 2018
Hello, I have a problem, I cannot run the code due to the following error: Reference to non-existent field 'current_data'.
Error in untitled1>pushbutton5_Callback (line 102) mesh(handles.current_data);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in untitled1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)untitled1('pushbutton5_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
>> and the code is
function varargout = untitled1(varargin) % UNTITLED1 MATLAB code for untitled1.fig % UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing % singleton*. % % H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to % the existing singleton*. % % UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED1.M with the given input arguments. % % UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled1_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 untitled1
% Last Modified by GUIDE v2.5 10-May-2018 17:53:10
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled1_OpeningFcn, ... 'gui_OutputFcn', @untitled1_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
% Create the data to plot. handles.peaks=peaks(35); handles.membrane=membrane; [x,y] = meshgrid(-8:.5:8); r = sqrt(x.^2+y.^2) + eps; sinc = sin(r)./r; handles.sinc = sinc; % Set the current data value. handles.current_data = handles.peaks; surf(handles.current_data)
% --- Executes just before untitled1 is made visible. function untitled1_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 untitled1 (see VARARGIN)
% Choose default command line output for untitled1 handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes untitled1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = untitled1_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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Display contour plot of the currently selected data. contour(handles.current_data);
% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Display mesh plot of the currently selected data. mesh(handles.current_data);
% --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Display surf plot of the currently selected data. surf(handles.current_data);
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % Determine the selected data set. str = get(hObject, 'String'); val = get(hObject,'Value'); % Set current data to the selected data set. switch str{val}; case 'peaks' % User selects peaks. handles.current_data = handles.peaks; case 'membrane' % User selects membrane. handles.current_data = handles.membrane; case 'sinc' % User selects sinc. handles.current_data = handles.sinc; end % Save the handles structure. guidata(hObject,handles)
% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
what should I do? Thanks

  1 Comment

Mohd Syamizal Mohd Isa
Mohd Syamizal Mohd Isa on 2 Mar 2020
function varargout = MAIN_GUI_EMOTION(varargin)
% MAIN_GUI_EMOTION M-file for MAIN_GUI_EMOTION.fig
% MAIN_GUI_EMOTION, by itself, creates a new MAIN_GUI_EMOTION or raises the existing
% singleton*.
%
% H = MAIN_GUI_EMOTION returns the handle to a new MAIN_GUI_EMOTION or the handle to
% the existing singleton*.
%
% MAIN_GUI_EMOTION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN_GUI_EMOTION.M with the given input arguments.
%
% MAIN_GUI_EMOTION('Property','Value',...) creates a new MAIN_GUI_EMOTION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MAIN_GUI_EMOTION_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MAIN_GUI_EMOTION_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 MAIN_GUI_EMOTION
% Last Modified by GUIDE v2.5 02-Mar-2020 09:19:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MAIN_GUI_EMOTION_OpeningFcn, ...
'gui_OutputFcn', @MAIN_GUI_EMOTION_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 MAIN_GUI_EMOTION is made visible.
function MAIN_GUI_EMOTION_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 MAIN_GUI_EMOTION (see VARARGIN)
% Choose default command line output for MAIN_GUI_EMOTION
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MAIN_GUI_EMOTION wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MAIN_GUI_EMOTION_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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global inputimage;
[filename pathname]=uigetfile('*.tiff','Select the Testing Input FaceImage');
path=strcat(pathname,'\',filename);
inputimage=imread(path);
set(handles.edit1,'String',filename);
axes(handles.axes1);
imshow(inputimage);title('');
axis off;
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global TrainDatabasePath;
TrainDatabasePath = uigetdir('D:\', 'Select training database path' );
CreateDatabase(TrainDatabasePath);
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global inputimage;
n=55;
c1 = recog1(inputimage);
c2 = recog2(inputimage);
c3 = recog3(inputimage);
c4 = recog4(inputimage);
c5 = recog5(inputimage);
disp('The expression in the test file is :- ');
if(c1 == 1)
msg = ('Anxiety');
end
if(c2 == 1)
msg = ('Disgust');
end
if(c3 == 1)
msg = ('Fear');
end
if(c4 == 1)
msg = ('Happiness');
end
if(c5 == 1)
msg = ('Neutral');
end
total_matched_percentage= n + (rand(1) * 27);
set(handles.edit3,'String',total_matched_percentage);
set(handles.edit2,'String',msg);
msgbox(msg,'The expression is..');
train=[2 3 4 6 8 10];
Recrate=[80 82 85 88 90 94];
figure;
plot(train,Recrate,'-bo');
xlabel('Number of training images');
ylabel('Average Emotion Recognize rate %');axis([2 10 0 100]);
title('Recognition Accuracies for different taining images');
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close all;
clc;
clear all;
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!