Problems with Nested functions

5 次查看(过去 30 天)
having lots of trouble with my program, alot of them would be solved if I could use nested functions, however my program will not let me use nested functions. Why? and anyways around this?
Function startup
load Exampledata.mat
function example
disp('hello world')
end
end
something even this simple will not work! Error result is
Error using load Attempt to add "clims" to a static workspace. See MATLAB Programming, Restrictions on Assigning to Variables for details.
Error in program (line 3) load ExampleData.mat

采纳的回答

Matt J
Matt J 2013-5-21
编辑:Matt J 2013-5-21
Call LOAD with an explicit output instead. Not doing so is bad for many reasons in addition to the error that it's giving you here.
Function startup
S=load('Exampledata.mat');
function example
disp('hello world')
end
end
  2 个评论
Hanif
Hanif 2013-5-22
Thanks that seems to do the trick, however anytime I try and call a variable in Exampledata.mat it is now undefined?
Matt J
Matt J 2013-5-22
编辑:Matt J 2013-5-22
The variables are fields of the structure output S. You should access them through that.

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-5-21
Check if ExampleData.mat is in your current folder
dir ExampleData.mat

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by