lexical scoping and namespaces
Mostrar comentarios más antiguos
This code...
function [] = foo()
bar();
baz();
function [] = bar()
a = 1;
end
function [] = baz()
if a
fprintf('Foo!\n');
end
end
end
...gives me this error...
Undefined function or variable 'a'.
Error in foo/baz (line 12)
if a
Error in foo (line 5)
baz();
...but this code...
function [] = foo()
bar();
a;
baz();
function [] = bar()
a = 1;
end
function [] = baz()
if a
fprintf('Foo!\n');
end
end
end
...gives me...
Foo!
Please explain what is going on here. Is there any documentation for this behavior? I would appreciate any documentation which can help me better understand Matlab's lexical scoping rules, and how symbols are imported into certain namespaces.
Thanks.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Workspace Variables and MAT Files en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!