App Designer: How to use input arguments from startupFcn in the section Properties?
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sam Donche
le 17 Juin 2020
Commenté : Sam Donche
le 18 Juin 2020
I'm new to MATLAB's App Designer. I'm trying to make an app that reads in a 3D matrix and shows axial, coronal and sagittal views. However, early steps have already proven to be difficult.
I'm using the startupFcn to give the 3D matrix as an input (function startupFcn(app, Img)). Then, I want to calculate some basic information from this input matrix (e.g. size) in the properties section to use in other callbackfunctions (see below). This results in the following error:
"Invalid default value for property 'size_Img' in class 'BoundingBox': Unable to resolve the name app.Img."
I have tried setting the input variable Img global and using the access property to public (as seen below), but I keep getting the same error. Am I doing something wrong?
Thanks in advance for the pointers!
Sam
properties (Access = private)
size_Img = size(app.Img) % Image Size
size_Sag = size_Img(1); % Image Saggital Size
size_Trans = size_Img(2); % Image Transverse Size
size_Front = size(3); % Image Frontal Size
...
end
properties (Access = public)
Img % Input image
end
0 commentaires
Réponse acceptée
Vinayak Mohite
le 18 Juin 2020
Hi Sam,
From my understanding of the question, the error is being produced because you are trying to set the properties when the component is being created (This works correctly only if the value to on RHS is constant (e.g. size_x = 2 will work but size_x = size(X) won't work). The component creation step happens before calling the startup function. At the component creation time, Img was not defined, and hence it is throwing error.
Instead of initializing the properties values at declaration time, you should set them when startup function is called.
Following is the code that you will find helpful.
properties (Access = private)
size_Img % Image Size
size_Sag % Image Saggital Size
size_Trans % Image Transverse Size
size_Front % Image Frontal Size
...
end
properties (Access = public)
Img % Input Image
end
function startupFcn(app)
app.size_Img = size(app.Img); % Image Size
app.size_Sag = app.size_Img(1); % Image Saggital Size
app.size_Trans = app.size_Img(2); % Image Transverse Size
app.size_Front = size(3); % Image Frontal Size
end
For understanding in detail, you can refer the following links
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!