MATLAB: Hi guys I need help for the final project, Im trying to create a gui that calculates the moment of inertia for different shapes. I ve tried the best please help

gui

function varargout = Momen_calculator(varargin)
% MOMEN_CALCULATOR MATLAB code for Momen_calculator.fig
% MOMEN_CALCULATOR, by itself, creates a new MOMEN_CALCULATOR or raises the existing
% singleton*.
%

% H = MOMEN_CALCULATOR returns the handle to a new MOMEN_CALCULATOR or the handle to
% the existing singleton*.
%
% MOMEN_CALCULATOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MOMEN_CALCULATOR.M with the given input arguments.
%
% MOMEN_CALCULATOR('Property','Value',...) creates a new MOMEN_CALCULATOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Momen_calculator_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Momen_calculator_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 Momen_calculator
% Last Modified by GUIDE v2.5 24-Jun-2016 22:52:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Momen_calculator_OpeningFcn, ...
'gui_OutputFcn', @Momen_calculator_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 Momen_calculator is made visible.
function Momen_calculator_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 Momen_calculator (see VARARGIN)
% Choose default command line output for Momen_calculator
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Momen_calculator wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Momen_calculator_OutputFcn(hObject, ~, 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 selection change in shape.
function shape_Callback(hObject, eventdata, handles)
% hObject handle to shape (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 shape contents as cell array
% contents{get(hObject,'Value')} returns selected item from shape
% --- Executes during object creation, after setting all properties.

function shape_CreateFcn(hObject, eventdata, handles)
% hObject handle to shape (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
% --- 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)
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
% --- Executes on button press in moment.
function moment_Callback(hObject, eventdata, handles)
% hObject handle to moment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val=get(hObjetct('Value'));
str=get(hObjetct('string'));
switch str(val)
case 'hoop'
g = imread('Hoop.png'); axes(handles.axes1)
imshow(g)
hoop= mass*r1^2;
handles.hoop=hoop;
case ('Disk')
s=imread('Disk.png'); axes(handles.axes1)
imshow(s)
disk=mass*.5*r1.^2;
handles.disk=disk;
case ('Sphere')
d=imread('Solid_sphere.png'); axes(handles.axes1)
imshow(d)
sphere= 0.4*m*r.^2;
handles.sphere=sphere;
case ('Spherical_shell')
x=imread('thin_spherical_shell.png'); axes(handles.axes1)
imshow(x)
spherical_shell=(2/3)*mass*r1^2;
handles.spherical_shell=spherical_shell;
case ('Thin_rod')
z=imread('Thin_rod.png'); axes(handles.axes1)
imshow(z)
thin_rod=(1/12)*mass*legnht.^2;
handles.thin_rod=thin_rod;
case ('Thin_rod_2')
c= imread('Thin_rod_2.png'); axes(handles.axes1)
imshow(c)
thin_rod_2=(1/3)*mass*legnht.^2;
handles.thin_rod_2=thin_rod_2;
case('Rectangular_plate')
b=imread('Rectangular_plate.png'); axes(handles.axes1)
imshow(b)
rectangular_plate=(1/12)*mass*((lenght_a.^2)+(lenght_b.^2));
handles.rectangular_plate=rectangular_plate;
case ('Hollow_cylinder')
f=imread('Rectangular_plate.png'); axes(handles.axes1)
imshow(f)
hollow_cylinder=.5*mass*((r1.^2)+(r2.^2));
handles.hollow_cylinder=hollow_cylinder;
end
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
return;
function mass_Callback(hObject, eventdata, handles)
% hObject handle to mass (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 mass as text
% str2double(get(hObject,'String')) returns contents of mass as a double
mass = str2double(get(hObject, 'String'));
% --- Executes during object creation, after setting all properties.
function mass_CreateFcn(hObject, eventdata, handles)
% hObject handle to mass (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 r1_Callback(hObject, eventdata, handles)
% hObject handle to r1 (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 r1 as text
% str2double(get(hObject,'String')) returns contents of r1 as a double
r1= str2double(get(hObject, 'String'));
% --- Executes during object creation, after setting all properties.
function r1_CreateFcn(hObject, eventdata, handles)
% hObject handle to r1 (see GCBO)
% eventdata reserved - to be defeined 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 r2_Callback(hObject, eventdata, handles)
% hObject handle to r2 (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 r2 as text
% str2double(get(hObject,'String')) returns contents of r2 as a double
r2 = str2double(get(hObject, 'String'));
% --- Executes during object cration, after setting all properties.
function r2_CreateFcn(hObject, eventdata, handles)
% hObject handle to r2 (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 lenght_Callback(hObject, eventdata, handles)
% hObject handle to lenght (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 lenght as text
% str2double(get(hObject,'String')) returns contents of lenght as a double
lenght = str2double(get(hObject, 'String'));
% --- Executes during object creation, after setting all properties.
function lenght_CreateFcn(hObject, eventdata, handles)
% hObject handle to lenght (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 len1_Callback(hObject, eventdata, handles)
% hObject handle to len1 (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 len1 as text
% str2double(get(hObject,'String')) returns contents of len1 as a double
lenght_a= str2double(get(hObject, 'String'));
% --- Executes during object creation, after setting all properties.
function len1_CreateFcn(hObject, eventdata, handles)
% hObject handle to len1 (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 lenb_Callback(hObject, eventdata, handles)
% hObject handle to lenb (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 lenb as text
% str2double(get(hObject,'String')) returns contents of lenb as a double
lenght_b= str2double(get(hObject, 'String'));
% --- Executes during object creation, after setting all properties.
function lenb_CreateFcn(hObject, eventdata, handles)
% hObject handle to lenb (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 meters.
function meters_Callback(hObject, eventdata, handles)
% hObject handle to meters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of meters
% --- Executes on button press in kiLOM.
function kiLOM_Callback(hObject, eventdata, handles)
% hObject handle to kiLOM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of kiLOM
% --- Executes on button press in Kilos.
function Kilos_Callback(hObject, eventdata, handles)
% hObject handle to Kilos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Kilos
% --- Executes on button press in grams.
function grams_Callback(hObject, eventdata, handles)
% hObject handle to grams (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

Best Answer

Change hObjetct to hObject
Related Question