func2str
関数ハンドルからの文字ベクトルの構成
説明
例
関数ハンドルから文字ベクトルへの変換
関数 cos
と無名関数の両方の関数ハンドルを作成してから、文字ベクトルに変換します。
fh = @cos; c = func2str(fh)
c = 'cos'
fh = @(x,y)sqrt(x.^2+y.^2);
c = func2str(fh);
disp(['Anonymous function: ' c])
Anonymous function: @(x,y)sqrt(x.^2+y.^2)
プログラムにより関数ハンドル名を文字ベクトルとして表示
単一入力について関数ハンドルを評価する関数を作成します。
作業フォルダー内のファイル evaluateHandle.m
に次の関数を作成します。
function evaluateHandle(fh,x) y = fh(x); str = func2str(fh); disp('For input value: ') disp(x) disp(['The function ' str ' evaluates to:']) disp(y) end
関数ハンドルを使用して、関数 sin
を pi/2
で評価します。
fh = @sin; x = pi/2; evaluateHandle(fh,x)
For input value: 1.5708 The function sin evaluates to: 1
関数ハンドルを使用して、指定された行列 A
について を評価します。
fh = @(x) x.^2+7; A = [1 2;0 1]; evaluateHandle(fh,A)
For input value: 1 2 0 1 The function @(x)x.^2+7 evaluates to: 8 11 7 8
入力引数
fh
— 文字ベクトルに変換するハンドル
関数ハンドル
文字ベクトルに変換するハンドル。関数ハンドルとして指定します。
ヒント
func2str
を使用して関数ハンドルを文字ベクトルに変換してから、str2func
を使用してハンドルに戻した場合、関数ハンドルに格納していた変数は失われます。
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
使用上の注意事項および制限事項:
入力引数が無名関数に関連付けられている場合、生成されるコードは文字ベクトル
'@(...)...'
を返します。
スレッドベースの環境
MATLAB® の backgroundPool
を使用してバックグラウンドでコードを実行するか、Parallel Computing Toolbox™ の ThreadPool
を使用してコードを高速化します。
この関数はスレッドベースの環境を完全にサポートしています。詳細については、スレッドベースの環境での MATLAB 関数の実行を参照してください。
バージョン履歴
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)