www.pudn.com > Closid30.rar > CLSPLIT.M, change:1997-01-07,size:1556b


function [a,b,c,d] = clsplit(s,ns) 
 
% [a,b,c,d] = clsplit(s,ns) 
% 
% Split a matrix present in s, into a decomposed form 
% [a  b; c  d] with [a] a square matrix with dimension ns. 
% 
% INPUTS:   
% s            : matrix with dimensions > ns. 
% ns (optional): integer, indicating the location of the split. 
%                By default, ns = size(s)-1 in case [s] is square. 
%                 
% OUTPUTS: 
% a, b, c, d: decomposition of matrix s according to s = [a b; c d]. 
  
%********************************************************************* 
% 
% (c) P.M.J. Van den Hof, november 1996. 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
 
% file         : clsplit.m 
% date         : 18 november 1996 
% last update  : 18 november 1996 
 
%**************************************************************************** 
 
% Error checks 
if ((nargin==0)|(nargin>2)), 
  help clsplit 
  return 
end 
 
[m,n] = size(s); 
 
if ((nargin<2)&(m~=n)), 
  error('a second input parameter is required in case s is non-square') 
  return 
elseif ((nargin<2)&(m==n)), 
  ns=n-1; 
  if (ns<=0), 
    error('matrix can not be split into the requested dimension'); 
  return 
  end; 
elseif (nargin==2), 
  [r,c]=size(ns); 
  if ((r~=1)|(c~=1)), 
    error('[ns] should be a scalar integer'); 
    return 
  end; 
  if ((ns>=min(m,n))|(ns<=0)), 
    error('matrix can not be split into the requested dimension'); 
  return 
  end 
end; 
a = s(1:ns,1:ns); 
b = s(1:ns,ns+1:n); 
c = s(ns+1:m,1:ns); 
d = s(ns+1:m,ns+1:n);