Why do I get unrecognized function or variable when calling constructor in app designer
3 次查看(过去 30 天)
显示 更早的评论
I want to call the constructor from another class in my app's properties like this:
properties (Access = private)
oBenignDataset = ImageData('\\10.1.1.70\Projekte\Projekt_2223\pr5ahbg121232\Data', 'benign');
oMalignantDataset = ImageData('\\10.1.1.70\Projekte\Projekt_2223\pr5ahbg121232\Data', 'malignant');
analyzer = FeatureAnalyzer(TFeature);
end
The error occures at "analyzer = FeatureAnalyzer(TFeature);". It works for the other classes' constructor (ImageData) but not for this one. I get the error:
Invalid default value for property 'analyzer' in class 'GUI_FINAL':
Unrecognized function or variable 'TFeature'.
The constructor in my class looks like this:
function obj = FeatureAnalyzer(TFeature)
obj.TFeature = TFeature;
end
How can I fix this error?
2 个评论
Chris
2023-1-27
编辑:Chris
2023-1-27
Can you invoke a TFeature from the command window while located in the app's parent directory, or do you get a similar error?
test = TFeature;
You should be able to do this successfully with ImageData:
test = ImageData('\\10.1.1.70\Projekte\Projekt_2223\pr5ahbg121232\Data', 'benign');
If the app needs to generate a variable called TFeature to use, then I don't think it can be done by setting a property value default. The property would have to be set in the app's StartupFcn.
采纳的回答
更多回答(1 个)
Walter Roberson
2023-1-28
TFeature is not a property or method of the class, and it does not exist at the time the properties list is being parsed. It is local to your constructor.
Class properties are initialized to defaults before the constructor is executed.
You will need to have the constructor use th TFeature passed in to set the property to an appropriate value.
3 个评论
Chris
2023-1-28
编辑:Chris
2023-1-28
@Kevin Gjoni properties you want functions in your app to have access to need to be declared in the properties block:
properties
% ...
TFeature
end
Refer to them using their namespace:
app.TFeature = howeverYouMakeATFeature;
analyzer = FeatureAnalyzer(app.TFeature);
If you only need a variable within a single function, then it doesn't need to be a property of the app. For example, the iterator in a for loop.
for k = 1:3
% Do something
end
doesn't need to be app.k.
You've defined it in the function and it will be forgotten when the function exits.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!