Take the coefficients of variables that don't have, for construction, any divisor. Take the coefficients of variables that don't have, for construction, any divisor. Prototype: [coefficient] = getCoefficientFromString(chr) Input: chr - String vector of an equation Output: coefficient - Wanted coefficient
0001 %Take the coefficients of variables that don't have, for construction, any divisor. 0002 % 0003 %Take the coefficients of variables that don't have, for construction, any 0004 %divisor. 0005 % 0006 %Prototype: [coefficient] = getCoefficientFromString(chr) 0007 % 0008 %Input: chr - String vector of an equation 0009 % 0010 %Output: coefficient - Wanted coefficient 0011 0012 function [ coefficient ] = getCoefficientFromString( chr ) 0013 0014 chr = strrep(chr,'+ ','+'); 0015 chr = strrep(chr,'- ','-'); 0016 pieces = strsplit(' ',chr); 0017 0018 i = 1; 0019 coefficient = 0; 0020 warning off 0021 while i <= length(pieces) 0022 if cellfun(@isempty,strfind(pieces(i),'/'))==true 0023 coefficient = strcat(coefficient,char(pieces(i))); 0024 end 0025 i = i + 1; 0026 end 0027 0028 warning on 0029 0030 return; 0031 0032 end