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)