mustBeFile
説明
例
入力が有効なファイル名であることを確認
関数 mustBeFile
を使用して、関数に渡されるファイル パスが有効であることを確認します。
関数 readLine
は、ファイルにアクセスする前に、ファイル パスが有効であることを確認します。
function r = readLine(path) arguments path {mustBeFile} end fid = fopen(path); r = fgetl(fid); fclose(fid) end
以下のようなフォルダーへのパスを関数 readLine
に渡すとエラーになります。
r = readLine("C:\Users\Public")
Error using readLine r = readLine("C:\Users\Public") ↑ Invalid argument at position 1. The following files do not exist: 'C:\Users\Public'.
入力引数
path
— ファイルへのパス
string スカラー | 文字ベクトル
ファイルへのパス。関数が実行されるコンテキストからのファイルが入ったフォルダーを含む、完全修飾ファイル名として指定します。
例: "H:\myfolder\myfile.txt"
データ型: char
| string
ヒント
mustBeFile
は、プロパティと関数の引数の検証で使用されるように設計されています。
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
バージョン履歴
R2020b で導入
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)