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

1 visualizzazione (ultimi 30 giorni)
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)

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by