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

1 次查看(过去 30 天)
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)

采纳的回答

Craig Cowled
Craig Cowled 2013-6-4
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by