Problems using structs in appdesigner as private properties

I have a problem when trying to get some variables out of a struct in order to use them as a property in my app. I tried the following:
properties (Access = private)
%%load results
phase = coder.load('phase.mat');
%%extract variables
s = phase.phase.StateGrid.Values(1,:);
The following error appears:
Undefined variable "phase" or class "phase.phase.StateGrid.Values".
If I use exactly the same lines in Matlab the code works. I also tried the following, but this did not help neither:
properties (Access = private)
%%load results
phase = coder.load('phase.mat');
%%extract variables
s = app.phase.phase.StateGrid.Values(1,:);

回答(1 个)

You're assuming that the code to initialize the phase property executes before the code to initialize the s property. I'm not sure that assumption is safe to make. I would probably:
  1. Make s a Dependent property whose get.s property accessor method retrieves the value of the phase property, or
  2. Declare that phase and s are properties, and possibly initialize phase in the properties block, but wait to initialize s until the constructor executes.

类别

帮助中心File Exchange 中查找有关 Call Java from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by