calling subfunctions with handle

1 vue (au cours des 30 derniers jours)
Muazma Ali
Muazma Ali le 15 Déc 2021
Modifié(e) : Benjamin Kraus le 15 Déc 2021
Hi! :)
I have funcntion with a subfunction containing a handle:
function h= tellsoner
x= 0;
h= @legg_til_soner;
function y= legg_til_soner;
x= x+1
y=x
end
end
% ......................I am wondering how I can call the subfunction to accumulate the values or am I supposed to call the parent function always..?

Réponses (1)

Benjamin Kraus
Benjamin Kraus le 15 Déc 2021
Modifié(e) : Benjamin Kraus le 15 Déc 2021
You can call a function from a function handle by appending parentheses to the end of the variable name, even if there are no input arguments.
fh = tellsoner;
out = fh()
x = 1
y = 1
out = 1
out = fh()
x = 2
y = 2
out = 2
out = fh()
x = 3
y = 3
out = 3
function h = tellsoner
x = 0;
h = @legg_til_soner;
function y = legg_til_soner
x = x+1
y = x
end
end

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by