Calling m file from class?

조회 수: 1 (최근 30일)
Danijel Domazet
Danijel Domazet 2020년 5월 13일
댓글: Walter Roberson 2020년 5월 13일
I have a class A, and a file myinit.m.
myinit.m contains many variable initializations which are needed by the class A.
This is how I am using it:
myinit;
a1 = A();
a1.Run();
I would like to avoid the first line where myinit is called. I tried putting myinit into class constructor, however the variables are not permanent, and they go out of scope once constructor is exited, so the A.Run() does not have this variables.
Is it possible to call myinit from within the class?
Note that A.Run() calls a Simulink simulation sim('model') and this model needs all the myinit variables.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 13일
If the variables were permanent in the class constructor, then at the time sim() was run, they would not be directly accessible, as it is necessary to qualify by the object in order to get at the values. And if you are going to have an object reference then you might as well toss all of the values into a struct and reference the struct within the object inside the simulink model,
obj.simvars.Frequency
for example. You would have myinit return the struct and then store the struct inside the object.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by