polyevl.m

来自「基于MATLAB的辅助设计 简述了矩阵分析的重要性」· M 代码 · 共 45 行

M
45
字号
function [array,key] = polyevl(string)

%POLYEVL is a MATLAB function which can be used to get the poly-
%     nomial within a string which does not contain the brackets.
%     This function is only called by TFMODEL.m

%    Author:  Ole Barup Sorensen, Rapid Data Ltd 

%    Copyright (c) 1989-94 by Rapid Data Ltd
%    Revision 10:29  07/02/94

str = string(2:length(string)); 
is = find(str=='+'|str=='-'); is = is+ones(size(1,length(is)));
array = []; key = 1; i0 = 1; is0 = []; 
for i=1:length(is)
   if (string(is(i)-1)~='e'), is0 = [is0 is(i)]; end
end,   is0 = [is0 length(string)+1]; 
for i=1:length(is0), 
   if (i0>1), if (string(i0-1)=='-'), i0=i0-1; end, end
   substr = string(i0:is0(i)-1); i0 = is0(i)+1;
   is = find(substr=='s'|substr=='S');
   if length(is) == 0, 
      k0 = 0; v1 = str2num(substr);
      if isempty(v1)==1, key=0; end
      if key==0, return; end
   elseif length(is)==1, 
      if (is==1), v1 = 1; 
      elseif (is==2&substr(1)=='-'), v1=-1; 
      else, v1 = str2num(substr(1:is-1));
      if isempty(v1)==1, key=0; end
         if key==0, return; end
      end,
      if is==length(substr), k0 = 1;
      else, k0 = str2num(substr(is+1:length(substr)));
      if isempty(k0)==1, key=0; end
         if key==0, return; end
         k0 = floor(k0); 
      end
   else, disp('Too many s'''); return; end
   if (length(array)<k0+1),  array(k0+1) = v1;
   else, array(k0+1) = array(k0+1)+v1; 
   end, key = 1; 
end
array = array(length(array):-1:1);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?