Filter löschen
Filter löschen

Problems with Nested functions

1 Ansicht (letzte 30 Tage)
Hanif
Hanif am 21 Mai 2013
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

Akzeptierte Antwort

Matt J
Matt J am 21 Mai 2013
Bearbeitet: Matt J am 21 Mai 2013
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 Kommentare
Hanif
Hanif am 22 Mai 2013
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 am 22 Mai 2013
Bearbeitet: Matt J am 22 Mai 2013
The variables are fields of the structure output S. You should access them through that.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 21 Mai 2013
Check if ExampleData.mat is in your current folder
dir ExampleData.mat

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by