%% Track State Names in Generalized State-Space Model
% Create a genss model with labeled state names. To do so, label the states of the component LTI models before connecting them. For instance, connect a two-state fixed-coefficient plant model and a one-state tunable controller.

A = [-1 -1; 1 0];
B = [1; 0];
C = [0 1];
D = 0;
G = ss(A,B,C,D);
G.StateName = {'Pstate1','Pstate2'};

C = tunableSS('C',1,1,1);

L = G*C;

%
% The genss model L preserves the state names of the components that created it. Because you did not assign state names to the tunable component C, the software automatically does so. Examine the state names of L to confirm them.

L.StateName

% The automatic assignment of state names to control design blocks allows you to trace which states in the generalized model are contributed by tunable components.
%
% State names are also preserved when you convert a genss model to a fixed-coefficient state-space model. To confirm, convert L to ss form.

Lfixed = ss(L);
Lfixed.StateName

% State unit labels, stored in the StateUnit property of the genss model, behave similarly.
% Copyright 2012 The MathWorks, Inc.