ans
最近计算的答案
语法
说明
ans
是在未指定输出参数的情况下返回输出时创建的变量。MATLAB® 创建了 ans
变量,并用该变量存储输出。建议不要在脚本或函数中更改或使用 ans
的值,因为该值可能会经常变化。
ans
特定于当前工作区。基础工作区和每个函数工作区可以有自己的 ans
实例。有关详细信息,请参阅基础和函数工作区。
示例
简单计算的结果
在命令行窗口中执行简单计算,而不将结果赋给变量。MATLAB 将结果存储在 ans
变量中。
2 + 2
ans = 4
在命令行窗口中执行简单计算,并将结果赋给变量 result
。
result = 4 + 4
result = 8
显示 result
的值,然后显示 ans
的值。MATLAB 显示 result
的值而不返回输出。因此,ans
的值保持不变。
result
result = 8
ans
ans = 4
调用返回输出的函数
假设您有函数 testFunc
,它返回输出但不指定输出变量。
function a = testFunc a = 75; end
调用 testFunc
。MATLAB 将返回的结果存储在 ans
中。
testFunc
ans = 75
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)