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.
  댓글 수: 1
Cordelle
Cordelle 2013년 6월 4일
when I run my program; the error message states the the 'end' statements are not permitted

댓글을 달려면 로그인하십시오.

추가 답변 (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