# Nested function global variable

10 visualizzazioni (ultimi 30 giorni)
Robbie Peck il 15 Ott 2015
Modificato: Thorsten il 15 Ott 2015
function T = fun(theta)
global m
m = theta^2;
end
function out = fun2(t)
out=( (1-m*t^2)*(1-t^2) );
end
I have the two functions above. When I call for fun, it does not seem to be working. I am new to Matlab so it would be greatly appreciated if someone could help my understanding. Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Thorsten il 15 Ott 2015
Modificato: Thorsten il 15 Ott 2015
Add global m to your fun2; I also used point-wise multiplication and exponentiation to make it work.
function T = fun(theta)
global m
m = theta^2;
end
function out = fun2(t)
global m
out=( (1-m*t.^2).*(1-t.^2) );
end
Alternatively, you could define fun2 as an anonymous function; note that here fun2 is already a function handle, so you have to pass with without the @ to quad:
function T = fun(theta)
global m
m = theta^2;
fun2 = @(t) (1-m*t.^2).*(1-t.^2)
end
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Robbie Peck il 15 Ott 2015
Thank you- It's the point wise stuff I'm not used to. I'm used to R!

Accedi per commentare.

### Più risposte (1)

Julia il 15 Ott 2015
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Directed Graphs 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