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

17 visualizaciones (últimos 30 días)
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 comentarios
Chris
Chris el 27 de En. de 2023
Editada: Chris el 27 de En. de 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.
Kevin Gjoni
Kevin Gjoni el 28 de En. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Kevin Gjoni
Kevin Gjoni el 28 de En. de 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.

Más respuestas (1)

Walter Roberson
Walter Roberson el 28 de En. de 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 comentarios
Chris
Chris el 28 de En. de 2023
Editada: Chris el 28 de En. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by