| MATLAB Function Reference | ![]() |
Graphical Interface
除了 exist 函數,也可以使用 Workspace browser 來檢查。選擇 MATLAB 的 View 選單裡的 Workspace 即可打開。
Syntax
exist item exist itemkinda = exist('item',...)
Description
item 的檔案名稱通常會有副檔名以免和其他相似檔名混淆。例如: exist('file.ext')。
MEX,MDL,及 P 檔案必須在 MATLAB 搜尋路徑中。若 item 被找到,但卻不在 MATLAB 搜尋路徑中,則 exist('item') 回傳 2,因為 item 被認定成不明型態的檔案。
其他型態檔案或目錄則不需在 MATLAB 搜尋路徑中。若那檔案或目錄不在搜尋路徑中,則 item 必須明確指定相對於 MATLABPATH 的 partial pathname 或相對於目前目錄的路徑。
若 item 是個 Java 類別,則 exist('item') 回傳 8。但如果 item 是個 Java 類別檔案,則 exist('item') 回傳 2。
exist item 若找到 kind
kind 的 item,回傳 1;反之,回傳 0。kind 參數包括:
|
只檢查變數。 |
|
只檢查內建的函數。 |
|
只檢查檔案或目錄。 |
|
只檢查目錄。 |
class |
只檢查 Java 類別。 |
a = exist('item',... 回傳那變數或檔案的狀態。)
Remarks
若要檢查不只一個變數的存在性,可使用 ismember 函數。例如:
a = 5.83;
c = 'teststring';
ismember({'a','b','c'},who)
ans =
1 0 1
Examples
下面例子是利用 exist 來檢查 MATLAB 函數是內建函數還是檔案:
type = exist('plot')
type =
5
在下面例子:對於 Welcome 這個 Java 類別,exist 回傳 8;而對於 Welcome.class 這個 Java 類別檔案,則回傳 2。
exist Welcome
ans =
8
exist javaclasses/Welcome.class
ans =
2
See Also
dir, help, lookfor, partialpath, what, which, who
| evalin | exit | ![]() |