Clear Filters
Clear Filters

Why do I get unrecognized function or variable when calling constructor in app designer

16 views (last 30 days)
I want to call the constructor from another class in my app's properties like this:
properties (Access = private)
oBenignDataset = ImageData('\\\Projekte\Projekt_2223\pr5ahbg121232\Data', 'benign');
oMalignantDataset = ImageData('\\\Projekte\Projekt_2223\pr5ahbg121232\Data', 'malignant');
analyzer = FeatureAnalyzer(TFeature);
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;
How can I fix this error?
Chris on 27 Jan 2023
Edited: Chris on 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('\\\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.
Kevin Gjoni
Kevin Gjoni on 28 Jan 2023
it works fine in the command window. It gives me a filled table. TFeature is a variable in the workspace, so it doesn't work when I clear my workspace.
Setting the property in the app's StartupFcn gave me the same error.

Sign in to comment.

Accepted Answer

Kevin Gjoni
Kevin Gjoni on 28 Jan 2023
I solved the problem:
The TFeature that i passed to the constructer is a table in the workspace. I don't know why but I could access it, so I tried to add it to the path. I did this by converting the table to an excel file which then is added to my path:
>> TFeature = evalin('base', 'TFeature');
>> writetable(TFeature,'TFeature.xlsx','FileType','spreadsheet')
To access the table in my app i used the readtable function (in my StartupFcn):
TFeature = readtable('TFeature.xlsx');
analyzer = FeatureAnalyzer(TFeature);
Then I was able to call the constructer without errors.

More Answers (1)

Walter Roberson
Walter Roberson on 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.
Chris on 28 Jan 2023
Edited: Chris on 28 Jan 2023
@Kevin Gjoni properties you want functions in your app to have access to need to be declared in the properties block:
% ...
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
doesn't need to be app.k.
You've defined it in the function and it will be forgotten when the function exits.

Sign in to comment.


Find more on Develop Apps Using App Designer in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!