Why do I get unrecognized function or variable when calling constructor in app designer
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Gjoni
am 27 Jan. 2023
Kommentiert: Kevin Gjoni
am 28 Jan. 2023
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 Kommentare
Chris
am 27 Jan. 2023
Bearbeitet: Chris
am 27 Jan. 2023
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.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 28 Jan. 2023
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 Kommentare
Chris
am 28 Jan. 2023
Bearbeitet: Chris
am 28 Jan. 2023
@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.
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!