Code covered by the BSD License  

Highlights from
Simscape Language Equations, Pretty Print

image thumbnail

Simscape Language Equations, Pretty Print

by

 

14 Jan 2011 (Updated )

MATLAB code for displaying Simscape language equations in a format that is easy to read.

concatMultipleLines(eqs)
function eqs = concatMultipleLines(eqs)
% Copyright 2011 The MathWorks, Inc.

% remove empty lines
eqs = eqs(~cellfun(@isempty,eqs));
%
pattern = '(\.{3})(.)*';
idx = regexp(eqs,pattern);
eqs = regexprep(eqs, pattern, '');
idx(cellfun(@isempty,idx)) = {0};
idxLogical = cellfun(@logical,idx);

bufeqs=repmat(cellstr(''),numel(eqs)-sum(idxLogical),1);
j=1;
idxLogical = [0 ; idxLogical];

for k=1:numel(eqs)
  if idxLogical(k+1)
    if idxLogical(k) == 0
      bufeqs{j,1} = [eqs{k} eqs{k+1}];
    else
      bufeqs{j,1} = [bufeqs{j,1} eqs{k+1}];
    end
  else
    if idxLogical(k) == 0
      bufeqs{j,1} = eqs{k};
    end
    j=j+1;
  end
end
eqs = bufeqs;

Contact us