MATLAB: Creating and using variables in same function

assigninmatlab guivariables

I am getting the following error with the following code. Any help would be appreciated. Thank you!
??? Undefined function or variable 'freq_GHz'.
Error in ==> RadarTool>pushbutton1_Callback at 114
freq_Hz = freq_GHz*1e9; %frequency in Hz

Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> RadarTool at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)RadarTool('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
My code is a GUI (created with GUIDE) which has some edit boxes to input variable values, and then a push button to execute some calculations with those variables. The error occurs when I try to use a variable that I created earlier in the same function (last line copied below).
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)
%read all of the edit box variables into the workspace
fprintf('Reading variables...')
assignin('base','NoiseTemp_K',str2double(get(handles.edit1,'String')));
assignin('base','RCS_m2dB',str2double(get(handles.edit2,'String')));
assignin('base','freq_GHz',str2double(get(handles.edit3,'String')));
assignin('base','TxGain_dB',str2double(get(handles.edit4,'String')));
assignin('base','Losses_dB',str2double(get(handles.edit5,'String')));
assignin('base','TxDutyFac',str2double(get(handles.edit6,'String')));
assignin('base','RxGain_dB',str2double(get(handles.edit7,'String')));
assignin('base','DFBW_Hz',str2double(get(handles.edit8,'String')));
assignin('base','Az',str2double(get(handles.edit9,'String')));
assignin('base','El',str2double(get(handles.edit10,'String')));
assignin('base','peakpower_W',str2double(get(handles.edit11,'String')));
assignin('base','Range_nmi',str2double(get(handles.edit12,'String')));
assignin('base','SNR_dB',str2double(get(handles.edit13,'String')));
display 'complete'
%constants and calculations
fprintf('Starting calculations...')
c=3e8; %speed of light in m/s
freq_Hz = freq_GHz*1e9; %frequency in Hz
I find the error confusing because I am able to run the same line of code outside of the function using either the MATLAB command line or a script. I thought that any variable created by the function in the base workspace would be accessible to that same function.

Best Answer

Thanks per isakson!
Here is how I solved the issue:
Created variables without assignin to start; e.g.:
NoiseTemp_K=str2double(get(handles.edit1,'String'));
Since I want the variables accessible after the function closes use assignin at the end of the function to save the variables I created inside the function:
assignin('base','NoiseTemp_K',NoiseTemp_K)
This way I can perform calculations on the variables inside the function