Bunch of Errors with Matlab GUI

1 visualizzazione (ultimi 30 giorni)
Mayhem Sussus
Mayhem Sussus il 19 Nov 2021
Commentato: Rik il 19 Nov 2021
Hello,
I have been trying to fix those error for quite some time now, but still haven't found the solution for them.
Code:
function varargout = ABS_gui(varargin)
% ABS_GUI MATLAB code for ABS_gui.fig
% ABS_GUI, by itself, creates a new ABS_GUI or raises the existing
% singleton*.
%
% H = ABS_GUI returns the handle to a new ABS_GUI or the handle to
% the existing singleton*.
%
% ABS_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ABS_GUI.M with the given input arguments.
%
% ABS_GUI('Property','Value',...) creates a new ABS_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ABS_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ABS_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 ABS_gui
% Last Modified by GUIDE v2.5 30-Apr-2013 15:11:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ABS_gui_OpeningFcn, ...
'gui_OutputFcn', @ABS_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 ABS_gui is made visible.
function ABS_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 ABS_gui (see VARARGIN)
% Choose default command line output for ABS_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ABS_gui wait for user response (see UIRESUME)
% uiwait(handles.figuremain);
% --- Outputs from this function are returned to the command line.
function varargout = ABS_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 pushbuttonExit.
function pushbuttonExit_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonExit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% delete(handles.figuremain)
labelStr = '<html><center><a href="">Undocumented<br>Matlab.com';
cbStr = 'web(''http://Undocumentedmatlab.com'');';
hButton = uicontrol('string',labelStr,'pos',[20,20,100,35],'callback',cbStr);
jButton = findjobj(hButton); % get FindJObj from the File Exchange
jButton.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton.setContentAreaFilled(0); % or: jButton.setBorder([]);
% --- Executes on button press in pushbuttonLoadXLS.
function pushbuttonLoadXLS_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonLoadXLS (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
handles.fileName = uigetfile('*.xls');
guidata(hObject,handles);
fileName = handles.fileName;
clear a cD PiD cF PiF Jw Js D ;
%Data Input
[cD,cF,Jw,Js] = ReadExcelData(fileName);
%load experimental data from excel spreadsheet
cD; %mM
cF; %mM
Jw; %L/m2h
Js; %mmol/m^-2h^-1
%Note: PiD and PiF are calculated internally using the van't Hoff equation [bar]
D = str2double(get(handles.editDiffusivity,'String')); %m2/s
T = str2double(get(handles.editTemperature,'String')); %K
IVs(1) = str2double(get(handles.editAo,'String')); %Lmh/bar
IVs(2) = str2double(get(handles.editBo,'String')); %Lmh
IVs(3) = str2double(get(handles.editSo,'String')); %micron
[A,B,S,R2w,R2s] = Compute_ABS_fmincon(Jw,Js,cD,cF,D,T,IVs);
%
set(handles.textoutputA,'String',num2str(A));
set(handles.textoutputB,'String',num2str(B));
set(handles.textoutputS,'String',num2str(S));
set(handles.textoutputR2w,'String',num2str(R2w));
set(handles.textoutputR2s,'String',num2str(R2s));
function editAo_Callback(hObject, eventdata, handles)
% hObject handle to editAo (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 editAo as text
% str2double(get(hObject,'String')) returns contents of editAo as a double
% --- Executes during object creation, after setting all properties.
function editAo_CreateFcn(hObject, eventdata, handles)
% hObject handle to editAo (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 editBo_Callback(hObject, eventdata, handles)
% hObject handle to editBo (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 editBo as text
% str2double(get(hObject,'String')) returns contents of editBo as a double
% --- Executes during object creation, after setting all properties.
function editBo_CreateFcn(hObject, eventdata, handles)
% hObject handle to editBo (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 editSo_Callback(hObject, eventdata, handles)
% hObject handle to editSo (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 editSo as text
% str2double(get(hObject,'String')) returns contents of editSo as a double
% --- Executes during object creation, after setting all properties.
function editSo_CreateFcn(hObject, eventdata, handles)
% hObject handle to editSo (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 editTemperature_Callback(hObject, eventdata, handles)
% hObject handle to editTemperature (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 editTemperature as text
% str2double(get(hObject,'String')) returns contents of editTemperature as a double
% --- Executes during object creation, after setting all properties.
function editTemperature_CreateFcn(hObject, eventdata, handles)
% hObject handle to editTemperature (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 editDiffusivity_Callback(hObject, eventdata, handles)
% hObject handle to editDiffusivity (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 editDiffusivity as text
% str2double(get(hObject,'String')) returns contents of editDiffusivity as a double
% --- Executes during object creation, after setting all properties.
function editDiffusivity_CreateFcn(hObject, eventdata, handles)
% hObject handle to editDiffusivity (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 edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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 pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%labelStr = '<html><center><a href="">Undocumented<br>Matlab.com';
labelStr = 'Elimelech Lab at Yale University';
cbStr = 'web(''http://www.yale.edu/env/elimelech/Research_Page/FO_characterization.html'');';
hButton = uicontrol('string',labelStr,'pos',[301,16,248,51],'callback',cbStr);
And the Errors:
Unrecognized field name "editDiffusivity".
Error in ABS_gui>pushbuttonLoadXLS_Callback (line 109)
D = str2double(get(handles.editDiffusivity,'String')); %m2/s
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ABS_gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ABS_gui('pushbuttonLoadXLS_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Thanks in advance. Regards.
  2 Commenti
Stephen23
Stephen23 il 19 Nov 2021
"...but still haven't found the solution for them."
Avoid GUIDE.
DGM
DGM il 19 Nov 2021
Attach the associated .fig file and anything else required to troubleshoot the figure setup.

Accedi per commentare.

Risposte (1)

Rik
Rik il 19 Nov 2021
GUIDE is infamous form auto-generating a lot of bloat. Let's first remove all that (and the init function, since that is the same for all GUIDE GUIs):
% --- Executes just before ABS_gui is made visible.
function ABS_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 ABS_gui (see VARARGIN)
% Choose default command line output for ABS_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function varargout = ABS_gui_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
function pushbuttonExit_Callback(hObject, eventdata, handles)
% delete(handles.figuremain)
labelStr = '<html><center><a href="">Undocumented<br>Matlab.com';
cbStr = 'web(''http://Undocumentedmatlab.com'');';
hButton = uicontrol('string',labelStr,'pos',[20,20,100,35],'callback',cbStr);
jButton = findjobj(hButton); % get FindJObj from the File Exchange
jButton.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton.setContentAreaFilled(0); % or: jButton.setBorder([]);
function pushbuttonLoadXLS_Callback(hObject, eventdata, handles)
clc;
handles.fileName = uigetfile('*.xls');
guidata(hObject,handles);
fileName = handles.fileName;
clear a cD PiD cF PiF Jw Js D ;
%Data Input
[cD,cF,Jw,Js] = ReadExcelData(fileName);
%load experimental data from excel spreadsheet
cD; %mM
cF; %mM
Jw; %L/m2h
Js; %mmol/m^-2h^-1
%Note: PiD and PiF are calculated internally using the van't Hoff equation [bar]
D = str2double(get(handles.editDiffusivity,'String')); %m2/s
T = str2double(get(handles.editTemperature,'String')); %K
IVs(1) = str2double(get(handles.editAo,'String')); %Lmh/bar
IVs(2) = str2double(get(handles.editBo,'String')); %Lmh
IVs(3) = str2double(get(handles.editSo,'String')); %micron
[A,B,S,R2w,R2s] = Compute_ABS_fmincon(Jw,Js,cD,cF,D,T,IVs);
%
set(handles.textoutputA,'String',num2str(A));
set(handles.textoutputB,'String',num2str(B));
set(handles.textoutputS,'String',num2str(S));
set(handles.textoutputR2w,'String',num2str(R2w));
set(handles.textoutputR2s,'String',num2str(R2s));
function pushbutton4_Callback(hObject, eventdata, handles)
%labelStr = '<html><center><a href="">Undocumented<br>Matlab.com';
labelStr = 'Elimelech Lab at Yale University';
cbStr = 'web(''http://www.yale.edu/env/elimelech/Research_Page/FO_characterization.html'');';
hButton = uicontrol('string',labelStr,'pos',[301,16,248,51],'callback',cbStr);
The source of this error means that the handle to your edit field is not correctly stored in the handles struct. You should double-check the name.
A much better idea however would be to abandon GUIDE and write the GUI yourself and only use GUIDE as a sketch pad. You are already most of the way there. For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
  1 Commento
Rik
Rik il 19 Nov 2021
What changes did you make? Did you already switch away from GUIDE?
What did you try to zero in on the cause? Did you set breakpoints to inspect the values of your variables and execute the code line by line?

Accedi per commentare.

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by