Clear Filters
Clear Filters

Predefined "Settings" in R2011b

1 view (last 30 days)
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

Accepted Answer

Matt Tearle
Matt Tearle on 1 Dec 2011
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 Comments
Alexander Mering
Alexander Mering on 1 Dec 2011
Thanks for the reply,
the last comment is exactly the point. This resolves the issue.
Strange thing, at least to me.
Thank you,
Alexander
Matt Tearle
Matt Tearle on 1 Dec 2011
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

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!