Filter löschen
Filter löschen

Predefined "Settings" in R2011b

1 Ansicht (letzte 30 Tage)
Alexander Mering
Alexander Mering am 1 Dez. 2011
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

Akzeptierte Antwort

Matt Tearle
Matt Tearle am 1 Dez. 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 Kommentare
Alexander Mering
Alexander Mering am 1 Dez. 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 am 1 Dez. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by