Predefined "Settings" in R2011b
1 次查看(过去 30 天)
显示 更早的评论
Dear Forum,
in R2010b I used a larger struct named "Settings", used to collect several settings. I saved this struct to a mat-file and tried to reload it later on. When accessing the (loaded) Settings, Matlab R2011b gives:
ans=
Settings handle with no properties.
Methods, Events, Superclasses
It seems, that in R2011b a new class named Settings came onto the field.
My question:
Is this problematic? How to override? Should I override? What would be the best choice to do?
Thanks for any answer,
Alexander
0 个评论
采纳的回答
Matt Tearle
2011-12-1
Where and how are you trying to reload them?
In 11b I get the following:
>> which Settings -all
Settings is a built-in method % Settings constructor
>> Settings = pi
Settings =
3.1416
>> which Settings -all
Settings is a variable.
Settings is a built-in method % Shadowed Settings constructor
So you're right that there is a name conflict, but a local variable should (as always) take precedence. So I'm wondering if this is a problem with zapping variables into existence inside a function.
If you have load foo in a function (and Settings is a variable in foo.mat) then you will run into name conflict problems. The solution is to use the functional form of load:
x = load('foo.mat');
Settings = x.Settings;
clear('x');
2 个评论
Matt Tearle
2011-12-1
Excellent, glad to hear that my MATLAB-Fu intuition is up to scratch :)
Can you accept the answer, so the question shows up as having been resolved? (That way, other answerers don't waste time on it.) Thanks!
If you're interested, here's my longer explanation of what's going on: http://www.mathworks.com/matlabcentral/answers/22497-code-assistance
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!