App Designer: How to use input arguments from startupFcn in the section Properties?
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam Donche
am 17 Jun. 2020
Kommentiert: Sam Donche
am 18 Jun. 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 Kommentare
Akzeptierte Antwort
Vinayak Mohite
am 18 Jun. 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
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!