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 个评论
采纳的回答
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!