matlab字符串能否运算
时间: 2023-11-21 09:56:55 浏览: 126
Matlab\字符串运算
是的,Matlab中的字符串可以进行运算。可以使用eval函数将字符串转换为可执行的表达式。例如,可以将一个字符串定义为平方根运算,然后使用eval函数计算1到10的平方根。示例代码如下:
```matlab
t = 'sqrt(i)';
for i = 1:10
s(i) = {char(['The square root of ', int2str(i), ' is ', num2str(eval(t))])};
end
s(:)
```
输出结果为:
```
ans =
10×1 cell 数组
{'The square root of 1 is 1'}
{'The square root of 2 is 1.4142'}
{'The square root of 3 is 1.7321'}
{'The square root of 4 is 2'}
{'The square root of 5 is 2.2361'}
{'The square root of 6 is 2.4495'}
{'The square root of 7 is 2.6458'}
{'The square root of 8 is 2.8284'}
{'The square root of 9 is 3'}
{'The square root of 10 is 3.1623'}
```
阅读全文