Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)MatlabGUI('Run_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.
Show older comments
Hello everyone, this is for my school project. I am trying to generate a GUI based on a optimisation code for a pressure vessel. The .m code for the pressure vessel works but I am not too sure whether my GUI code is written correctly and an error pops up when I try to run the code. Could someone please help me find this problem?
%----------------------------------------
%This script generates the user input for internal pressure, desired
%capacity, desired safety factor, maximum total length,and maximum height,
%as well as the parameters of length, internal radius. This code solves
%the optimisation problem for a pressure vessel, it loads a .mat file '...' which
%contains the information for different materials, in order to find the
%optimum values of thickness, internal radius, length and volume (cost).
%This data is then used in a GUI and displayed to the user.
%-----------------------------------------
%Initialisation
clc
clear
format compact
format short g
load('materialfile.mat')
%-----------------------------------------
% Inputs part 1: Problem inputs
p=5.8565; %Bar
c=95620; %L
stress_all=150e6; %Pa
Nd=2;
maxH=3.5; %m
maxL=11; %m
%Inputs part 2: search parameters
Ri_lowerbound=0;
Ri_interval=0.005;
Ri_upperbound=1.5; % researched online and found average
L_lowerbound=0;
L_interval=0.05;
L_upperbound=7.9; % derived from Ri upperbound and formula
%Inputs part 3: Unit conversions
p=p*10^5; %Pa
c=c*0.001; %cubic meters
%-------------------------------------------
%Exhaustive search
solutions=[];
for i=1:1:length(material);
material_picked=i;
Sy= material(i).sy*10^6; % tells matlab to pick the sy column
CF= material(i).cf; % tells matlab to pick the cf column
allow_stress=Sy./Nd
for j=1:1:length(material(i).t); % tells matlab to pick the material thickness
t= material(i).t(j)*10^-3; % tells matlab for converting units for thickness from chose material
for Ri=0:0.005:(maxH-2*t)/2;
L=(c-((4*pi*Ri^3)/3))/(pi*Ri^2)
Ro=Ri+t
Lt=L+Ro.*2
H=Ro.*2
Vi=((Ri.^2).*pi.*L)+((Ri.^3).*pi.*4./3)
Vm=(Ri.*t.*L.*2.*pi)+(Ri.^2.*t.*4.*pi)
CI=Vm.*CF
if Vi==c;
if t/Ri >=0.05
tstress=((Ri.^2.*p)./(Ro.^2-Ri.^2).*(1+(Ro.^2./Ri.^2)))
rstress=((Ri.^2.*p)./(Ro.^2-Ri.^2).*(1-(Ro.^2./Ri.^2)))
lstress=(Ri.^2.*p)./(Ro.^2-Ri.^2)
thicknesscase_type=1
else
tstress=(Ri.*p)./t
rstress=0
lstress=(Ri.*p)./(2.*t)
thicknesscase_type=0
end
vonmises_stress=sqrt(((tstress-rstress).^2+(tstress-lstress).^2+(lstress-rstress).^2)./2)
if vonmises_stress < allow_stress && Lt <= maxL && H <= maxH;
solutions = [solutions; Ri, L, t, material_picked, thicknesscase_type, allow_stress, vonmises_stress, Vm, Lt, H, CI]
end
end
end
end
end
disp(solutions)
The code above is my .m code for the pressure vessel.
function varargout = MatlabGUI(varargin)
% MATLABGUI MATLAB code for MatlabGUI.fig
% MATLABGUI, by itself, creates a new MATLABGUI or raises the existing
% singleton*.
%
% H = MATLABGUI returns the handle to a new MATLABGUI or the handle to
% the existing singleton*.
%
% MATLABGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MATLABGUI.M with the given input arguments.
%
% MATLABGUI('Property','Value',...) creates a new MATLABGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MatlabGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MatlabGUI_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 MatlabGUI
% Last Modified by GUIDE v2.5 19-Feb-2021 20:59:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MatlabGUI_OpeningFcn, ...
'gui_OutputFcn', @MatlabGUI_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 MatlabGUI is made visible.
function MatlabGUI_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 MatlabGUI (see VARARGIN)
% Choose default command line output for MatlabGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MatlabGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MatlabGUI_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 Pressure_Callback(hObject, eventdata, handles)
% hObject handle to Pressure (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 Pressure as text
% str2double(get(hObject,'String')) returns contents of Pressure as a double
% --- Executes during object creation, after setting all properties.
function Pressure_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pressure (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 CapacityC_Callback(hObject, eventdata, handles)
% hObject handle to CapacityC (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 CapacityC as text
% str2double(get(hObject,'String')) returns contents of CapacityC as a double
% --- Executes during object creation, after setting all properties.
function CapacityC_CreateFcn(hObject, eventdata, handles)
% hObject handle to CapacityC (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 Safetyfactor_Callback(hObject, eventdata, handles)
% hObject handle to Safetyfactor (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 Safetyfactor as text
% str2double(get(hObject,'String')) returns contents of Safetyfactor as a double
% --- Executes during object creation, after setting all properties.
function Safetyfactor_CreateFcn(hObject, eventdata, handles)
% hObject handle to Safetyfactor (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 Lt_Callback(hObject, eventdata, handles)
% hObject handle to Lt (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 Lt as text
% str2double(get(hObject,'String')) returns contents of Lt as a double
% --- Executes during object creation, after setting all properties.
function Lt_CreateFcn(hObject, eventdata, handles)
% hObject handle to Lt (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 H_Callback(hObject, eventdata, handles)
% hObject handle to H (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 H as text
% str2double(get(hObject,'String')) returns contents of H as a double
% --- Executes during object creation, after setting all properties.
function H_CreateFcn(hObject, eventdata, handles)
% hObject handle to H (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function Ri_Callback(hObject, eventdata, handles)
% hObject handle to Ri (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 Ri as text
% str2double(get(hObject,'String')) returns contents of Ri as a double
% --- Executes during object creation, after setting all properties.
function Ri_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ri (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 L_Callback(hObject, eventdata, handles)
% hObject handle to L (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 L as text
% str2double(get(hObject,'String')) returns contents of L as a double
% --- Executes during object creation, after setting all properties.
function L_CreateFcn(hObject, eventdata, handles)
% hObject handle to L (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 Run.
function Run_Callback(hObject, eventdata, handles)
% hObject handle to Run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
Pressure=str2double(get(handles.Pressure, 'string'));
Capacity=str2double(get(handles.Capacity, 'string'));
Nd=str2double(get(handles.Nd, 'string'));
Lt=str2double(get(handles.Lt, 'string'));
H=str2double(get(handles.H, 'string'));
Ri=str2double(get(handes.Ri, 'string'));
L=str2double(get(handes.L, 'string'));
maxH=3.5; %m
maxL=11; %m
%Inputs part 2: search parameters
Ri_lowerbound=0;
Ri_interval=0.005;
Ri_upperbound=1.5; % researched online and found average
L_lowerbound=0;
L_interval=0.05;
L_upperbound=7.9; % derived from Ri upperbound and formula
%Inputs part 3: Unit conversions
p=p*10^5; %Pa
c=c*0.001; %cubic meters
%-------------------------------------------
%Exhaustive search
solutions=[];
for i=1:1:length(material);
material_picked=i;
Sy= material(i).sy*10^6; % tells matlab to pick the sy column
CF= material(i).cf; % tells matlab to pick the cf column
allow_stress=Sy./Nd
for j=1:1:length(material(i).t); % tells matlab to pick the material thickness
t= material(i).t(j)*10^-3; % tells matlab for converting units for thickness from chose material
for Ri=0:0.005:(maxH-2*t)/2;
L=(c-((4*pi*Ri^3)/3))/(pi*Ri^2)
Ro=Ri+t
Lt=L+Ro.*2
H=Ro.*2
Vi=((Ri.^2).*pi.*L)+((Ri.^3).*pi.*4./3)
Vm=(Ri.*t.*L.*2.*pi)+(Ri.^2.*t.*4.*pi)
CI=Vm.*CF
if Vi==c;
if t/Ri >=0.05
tstress=((Ri.^2.*p)./(Ro.^2-Ri.^2).*(1+(Ro.^2./Ri.^2)))
rstress=((Ri.^2.*p)./(Ro.^2-Ri.^2).*(1-(Ro.^2./Ri.^2)))
lstress=(Ri.^2.*p)./(Ro.^2-Ri.^2)
thicknesscase_type=1
else
tstress=(Ri.*p)./t
rstress=0
lstress=(Ri.*p)./(2.*t)
thicknesscase_type=0
end
vonmises_stress=sqrt(((tstress-rstress).^2+(tstress-lstress).^2+(lstress-rstress).^2)./2)
if vonmises_stress < allow_stress && Lt <= maxL && H <= maxH;
solutions = [solutions; Ri, L, t, material_picked, thicknesscase_type, allow_stress, vonmises_stress, Vm, Lt, H, CI]
end
end
end
end
end
set(handles.product, 'string', solutions);
The code above is the GUI code.
4 Comments
Walter Roberson
on 20 Feb 2021
vi==c will probably never happen. You have two floating point expressions being calculated different ways but you are expecting bit-for-bit equality.
Walter Roberson
on 20 Feb 2021
We do not have your mat file and we do not know what inputs you gave. You also did not show us what matlab thought the error is: could not find a function? index out of range? mismatch of dimensions doing an assignment?
Kurtis Turek
on 25 Feb 2021
unluckyyyyyyyy
Geoff Hayes
on 26 Feb 2021
Adrian - when you say that you "run the code", how are you launching the GUI? Are you launching it from the MATLAB file editor by pressing the green button while editing the m file? Are you calling the m-file from the command line? Or are you trying to launch the GUI by double-clicking (or opening) the fig file? This last way - trying to launch the figure - will not work and sometimes can lead to errors that you are seeing. You need to launch GUIDE GUIs from the GUIDE editor, the MATLAB file editor, or from the console using the name of the GUI...and not calling the *.fig file.
Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!