No BSD License  

Highlights from
MPC: Multivariable Constrained State Space example

from MPC: Multivariable Constrained State Space example by Paul Mc Namara
A constrained MPC stirred tank reactor example

separate( A )
%separate z matrices into long matrix made up of matrices corresponding to
%different descending powers of z
function sepd = separate( A )

maxm = 1;

%find what the max number coefficients in matrix
for r = 1:size( A, 1 )
    for c = 1:size( A, 2 )
        h = size( A.num{ r, c }, 2 );
        
        if( maxm < h )
            maxm = h;
        end
        
    end        
end

%create a matrix to fit all the coefficients
sepd = zeros( size( A, 1 ), maxm*size( A, 2 ) );

%create matrices in sepd representing coeffs of descending z powers

    
for r = 1:size( A, 1 )
    for c = 1:size( A, 2 )
        h = size( A.num{ r, c }, 2 );
        
        %places value in necessary array position
        for i = 0:h-1
           sepd( r, c+i*size( A, 2 ) ) = A.num{ r, c }( i+1 );
        end
        
    end        
end

    

Contact us at files@mathworks.com