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

3 ビュー (過去 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.
  1 件のコメント
Cordelle
Cordelle 2013 年 6 月 4 日
when I run my program; the error message states the the 'end' statements are not permitted

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by