可以用eval()函数
y=eval('expression defined by user')
对于你的问题
x1=1;x2=2;x3=3; % need to be initialized
uexp = input('please input your expression: ')
y=eval(uexp)
注意:当matlab提示输入表达式时,必须要以字符串的形式输入。
以下是测试运行的过程:
>> x1=1;x2=2;x3=3; % need to be initialized
uexp = input('please input your expression: ')
y=eval(uexp)
please input your expression: 'x1+x2+x3'
uexp =
x1+x2+x3
y =
6
>> x1=1;x2=2;x3=3; % need to be initialized
uexp = input('please input your expression: ')
y=eval(uexp)
please input your expression: 'x2*x3-x1'
uexp =
x2*x3-x1
y =
5
[此贴子已经被作者于2008-6-14 10:42:23编辑过]