Predefined "Settings" in R2011b

조회 수: 1 (최근 30일)
Alexander Mering
Alexander Mering 2011년 12월 1일
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

채택된 답변

Matt Tearle
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
Alexander Mering
Alexander Mering 2011년 12월 1일
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 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by