App designer: How to define self-referring properties?
조회 수: 6 (최근 30일)
이전 댓글 표시
I'm getting into app designer once again, and right from the start I'm getting desperate.
When defining a property, I receive a nasty error message, I don't really comprehend.
Unrecognized function or variable 'x'
Referring to the little thing I have written:
properties (Access = private)
x = linspace(0,1);
VStep = ones(1,length(x));
VWell= zeros(1,length(x));
end
Why this result into an error? Actually it should simply define these variables to be accessible for future functions, but for some reason it won't pass x as a variable. I tried app.x, x.value etc and ALOT of other variations, but why Matlab makes it that complicated?
Where is the non-intuitive logic that will make it work?
댓글 수: 2
Rik
2023년 1월 27일
How did you make sure this is even possible without inheriting from a parent class?
채택된 답변
Steven Lord
2023년 1월 27일
That code does not define a variable named x. It defines an object property named x.
You're assuming that defining one property on an object can use the values of other properties on that object, but what guarantee do you have about the order in which those properties are defined? What if MATLAB tried to create the value for the property VStep before it created the value for the property x?
You can do what you want using Constant properties. These are properties that, as the attribute name implies, are constant across all instances of that class. This means you can refer to them using the class name rather than needing to query a class instance. In the example below x and Y are defined using the Hidden private Constant property N.
q = example1901875
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!