Code covered by the BSD License  

Highlights from
Removing Simulink's State Order Dependency (Example 3)

Removing Simulink's State Order Dependency (Example 3)

by

Dan Lluch (view profile)

 

02 Feb 2004 (Updated )

Explores how to leverage the 'Structure with Time' Simulink data format to alleviate ordering ...

makestatestruct(mdl)
function xstruct = makestatestruct(mdl)
%
% MAKESTATESTRUCT - Return all the double value states of a Simulink model.

[sys,x0,stateblocks,ts,xts]=feval(mdl,[],[],[],0);

%% Get the initial condition and sample time info from the model [sys,x0,stateblocks,ts,xts]=feval(model,[],[],[],0);

%% Find the unique state names
[uniquestates,uind] = unique(stateblocks);
uniquexts = xts(uind);

%% Create the structure
for ct = length(uniquestates):-1:1
    ind = find(strcmp(uniquestates(ct),stateblocks));
    if uniquexts(ct) == 0
        xsignal(ct) = struct('values',x0(ind),'dimensions',length(ind),...
            'label','CSTATE','blockName',uniquestates(ct));
    else
        xsignal(ct) = struct('values',x0(ind),'dimensions',length(ind),...
            'label','DSTATE','blockName',uniquestates(ct));
    end
end

if ~isempty(uniquestates)
    xstruct = struct('time',[],'signals',xsignal);
else
    xstruct = struct('time',[],'signals',[]);
end

Contact us