why wont my gui update data

5 views (last 30 days)
Roxana Richter
Roxana Richter on 14 Apr 2015
Answered: Roxana Richter on 14 Apr 2015
okay so I am learning how to build a gui this is very basic I can not figure out why my resultant,resultant angle, the table or the graphs are not updating. I am probably missing something extremely basic. Please help.
function varargout = Statics_Components(varargin) %STATICS_COMPONENTS M-file for Statics_Components.fig % STATICS_COMPONENTS, by itself, creates a new STATICS_COMPONENTS or raises the existing % singleton*. % % H = STATICS_COMPONENTS returns the handle to a new STATICS_COMPONENTS or the handle to % the existing singleton*. % % STATICS_COMPONENTS('Property','Value',...) creates a new STATICS_COMPONENTS using the % given property value pairs. Unrecognized properties are passed via % varargin to Statics_Components_OpeningFcn. This calling syntax produces a % warning when there is an existing singleton*. % % STATICS_COMPONENTS('CALLBACK') and STATICS_COMPONENTS('CALLBACK',hObject,...) call the % local function named CALLBACK in STATICS_COMPONENTS.M with the given input % arguments. % % *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 Statics_Components
% Last Modified by GUIDE v2.5 13-Apr-2015 16:46:30
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Statics_Components_OpeningFcn, ... 'gui_OutputFcn', @Statics_Components_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 Statics_Components is made visible. function Statics_Components_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 unrecognized PropertyName/PropertyValue pairs from the % command line (see VARARGIN) axes(handles.Original_Forces) set(handles.Force1,'String',15) set(handles.Force2,'String',22) set(handles.Force3,'String',35) set(handles.Angle1,'String',52) set(handles.Angle2,'String',19) set(handles.Angle3,'String',3) [Fxo1, Fyo1]=Force_comps(15,52); [Fxo2, Fyo2]=Force_comps(22,19); [Fxo3, Fyo3]=Force_comps(35,3); Comp={Fxo1, Fyo1; Fxo2, Fyo2; Fxo3, Fyo3}; set(handles.Components,'data',Comp,'Enable','off') Sum_Fyo=Fyo1+Fyo2+Fyo3 Sum_Fxo=Fxo1+Fxo2+Fxo3 Resultanto=(Sum_Fxo^2+Sum_Fyo^2)^.5; set(handles.Resultant,'String',Resultanto,'Enable','off') Res_ango=atand(Sum_Fyo/Sum_Fxo) set(handles.Resultant_Angle,'String',Res_ango,'Enable','off') compass(Fxo1,Fyo1,'--b'); hold on; compass(Fxo2,Fyo2,'--k'); hold on; compass(Fxo3,Fyo3,'--g'); hold on; axes(handles.Resultant_Force) compass(Sum_Fxo,Sum_Fyo,'--r'); hold on; % Choose default command line output for Statics_Components handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Statics_Components wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Statics_Components_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 Force1_Callback(hObject, eventdata, handles) % hObject handle to Force1 (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 Force1 as text
% str2double(get(hObject,'String')) returns contents of Force1 as a double
axes(handles.Original_Forces)
cla;
F1=str2double(get(handles.Force1,'String')); %gets Force1 value
if isnan(F1)
F1=0;
set(handles.Force1,'String',0)
errordlg('Please only enter numbers');
end
% --- Executes during object creation, after setting all properties.
function Force1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Force1 (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 Force2_Callback(hObject, eventdata, handles) % hObject handle to Force2 (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 Force2 as text
% str2double(get(hObject,'String')) returns contents of Force2 as a double
axes(handles.Original_Forces)
cla;
F2=str2double(get(handles.Force2,'String'));
if isnan(F2)
F2=0;
set(handles.Force2,'String',0)
errordlg('Please only enter numbers');
end
% --- Executes during object creation, after setting all properties.
function Force2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Force2 (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 Force3_Callback(hObject, eventdata, handles) % hObject handle to Force3 (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 Force3 as text
% str2double(get(hObject,'String')) returns contents of Force3 as a double
axes(handles.Original_Forces)
cla;
F3=str2double(get(handles.Force3,'String'));
if isnan(F3)
F3=0;
set(handles.Force3,'String',0)
errordlg('Please only enter numbers');
end
% --- Executes during object creation, after setting all properties.
function Force3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Force3 (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 Angle1_Callback(hObject, eventdata, handles) % hObject handle to Angle1 (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 Angle1 as text
% str2double(get(hObject,'String')) returns contents of Angle1 as a double
A1=str2double(get(handles.Angle1,'String'));
if isnan(A1)
A1=0;
set(handles.Angle1,'String',0);
errordlg('Please only enter numbers')
pause(5)
end
% --- Executes during object creation, after setting all properties.
function Angle1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Angle1 (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 Angle2_Callback(hObject, eventdata, handles) % hObject handle to Angle2 (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 Angle2 as text
% str2double(get(hObject,'String')) returns contents of Angle2 as a double
A2=str2double(get(handles.Angle2,'String'));
if isnan(A2)
A2=0;
set(handles.Angle2,'String',0);
errordlg('Please only enter numbers')
pause(5)
end
% --- Executes during object creation, after setting all properties.
function Angle2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Angle2 (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 Angle3_Callback(hObject, eventdata, handles) % hObject handle to Angle3 (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 Angle3 as text
% str2double(get(hObject,'String')) returns contents of Angle3 as a double
A3=str2double(get(handles.Angle3,'String'));
if isnan(A3)
A3=0;
set(handles.Angle3,'String',0);
errordlg('Please only enter numbers')
pause(5)
end
% --- Executes during object creation, after setting all properties.
function Angle3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Angle3 (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 Resultant_Callback(hObject, eventdata, handles) % hObject handle to Resultant (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 Resultant as text
% str2double(get(hObject,'String')) returns contents of Resultant as a double
axes(handles.Original_Forces)
cla;
F1=str2double(get(handles.Force1,'String'))
F2=str2double(get(handles.Force2,'String'))
F3=str2double(get(handles.Force3,'String'))
A1=str2double(get(handles.Angle1,'String'))
A2=str2double(get(handles.Angle2,'String'))
A3=str2double(get(handles.Angle3,'String'))
[Fx1, Fy1]=Force_comps(F1,A1)
[Fx2, Fy2]=Force_comps(F2,A2)
[Fx3, Fy3]=Force_comps(F3,A3)
Comp={Fx1, Fy1; Fx2, Fy2; Fx3, Fy3};
set(handles.Components,'data',Comp,'Enable','off')
axes(handles.Resultant_Force)
cla;
Sum_Fy=Fy1+Fy2+Fy3
Sum_Fx=Fx1+Fx2+Fx3
handles.Rx=Sum_Fx
handles.Ry=Sum_Fy
Resultant=(Sum_Fx^2+Sum_Fy^2)^.5;
R=num2str(Resultant)
set(handles.Resultant,'String',R,'Enable','off')
compass(Fx1,Fy1,'--b'); hold on;
compass(Fx2,Fy2,'--k'); hold on;
compass(Fx3,Fy3,'--g'); hold on;
compass(Sum_Fx,Sum_Fy,'--r'); hold on;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Resultant_CreateFcn(hObject, eventdata, handles)
% hObject handle to Resultant (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 Resultant_Angle_Callback(hObject, eventdata, handles)
% hObject handle to Resultant_Angle (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 Resultant_Angle as text
% str2double(get(hObject,'String')) returns contents of Resultant_Angle as a double
Res_ang=atand(handles.Ry/handles.Rx)
set(handles.Resultant_Angle,'String',Res_ang,'Enable','off')
% --- Executes during object creation, after setting all properties.
function Resultant_Angle_CreateFcn(hObject, eventdata, handles)
% hObject handle to Resultant_Angle (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 Calculate. function Calculate_Callback(hObject, eventdata, handles) % hObject handle to Calculate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
  1 Comment
Image Analyst
Image Analyst on 14 Apr 2015
Just attach the fig file and m-file with the paper clip icon. And tell us which controls are not updating and what we have to do to illustrate the problem (what do we type or click to see that something is not updating).

Sign in to comment.

Answers (2)

Jan
Jan on 14 Apr 2015
The debugger is a marvelous tool to find out, what's going on in the code. Set a breakpoint at the start of each callback and step throught the code line by line. Then the problem is revealed most likely.

Roxana Richter
Roxana Richter on 14 Apr 2015
I figured it out I added a push button to trigger the calculations and moved my code to the push button Call back. I guess I just needed to sleep on it.

Community Treasure Hunt

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

Start Hunting!