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,:);

Answers (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.

Asked:

on 10 Oct 2016

Answered:

on 10 Oct 2016

Community Treasure Hunt

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

Start Hunting!