App designer: How to define self-referring properties?
2 ビュー (過去 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!