matlab-字串与数字转换,执行字符串和函数

 数字转字符

 

>> a=111

a =

   111

>> mat2str(a,'class')

ans =

double(111)

>> class(a)

ans =

double
>> num2str(a,'%10.2e')

ans =

1.11e+002

>>

 

 

字符转数字

>> double('abcdef')

ans =

    97    98    99   100   101   102

>>

>> str2num('66.123')

ans =

   66.1230

 

 

 

 

 

执行字符串

 

>> eval('666+99/2')

ans =

  715.5000

 

>> eval('aa=23455')

aa =

       23455

>>

 

执行函数

>> help feval
 FEVAL Execute the specified function.
    FEVAL(F,x1,...,xn) evaluates the function specified by a function
    handle or function name, F, at the given arguments, x1,...,xn.
    For example, if F = @foo, FEVAL(F,9.64) is the same as foo(9.64).
 
    If a function handle is bound to more than one built-in or
    M-file, (that is, it represents a set of overloaded functions),
    then the data type of the arguments x1 through xn, determines
    which function is executed.
 
    FEVAL is usually used inside functions which take function
    handles or function strings as arguments.  Examples include
    FZERO and EZPLOT.
 
    [y1,..,yn] = FEVAL(F,x1,...,xn) returns multiple output arguments.
 
    Within methods that overload built-in functions, use BUILTIN(F,...)
    to execute the original built-in function.  Note that when using
    BUILTIN, F must be a function name and not a function handle.
 

你可能感兴趣的:(matlab)