フィルターのクリア

App Designer: How to use input arguments from startupFcn in the section Properties?

25 ビュー (過去 30 日間)
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

採用された回答

Vinayak Mohite
Vinayak Mohite 2020 年 6 月 18 日
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. https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
  2. https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html
  1 件のコメント
Sam Donche
Sam Donche 2020 年 6 月 18 日
Thank you for the pointers!
I figured out that I was doing two things wrong:
  • Don't do any calculations when properties are being created (like you pointed out)
  • I need to set app.Img = Img in the startupFcn (as seen below). I figured that matlab would know that those two were equal.
function startupFcn(app, Img)
app.Img = Img;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDisplay and Exploration についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by