MATLAB: How do you share a variable from another function to be used in a different function

#sharingfunctionsbetweenfunctionsduplicate post requiring merging

function Browse1_Callback(~, ~, handles)
% hObject handle to Browse1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[FileName,FilePath ]= uigetfile();
ExPath1 = fullfile(FilePath, FileName);
set(handles.Filename1,'string',ExPath1)
(I would like to use the ExPath1 variable and value from my Browse1 function in my calculate1 function)
function Calculate1_Callback(~, ~, ~)
% hObject handle to Calculate1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%[x, error, stat1, stat2, stat3] = correctionModelworking1('landsat5.xls', 'true', 2,'true');
[x, error, stat1, stat2, stat3] = correctionModelworking1(ExPath1,'true',2,'true');
(Right now the code doesnt work but i needed help fixing it)

Best Answer

Cordelle, I'm not going to re-write your code for you, but I will suggest that you read up on nested functions,
From what I can see in your code, you are missing two 'end' statements. Doing this will ensure that your second function is nested within the first function. All the variables declared in the first function will be available to the second function, much like global variables.
Have fun, Craig.