matlab check existence

exist

Check existence of variable, script, function, folder, or class

Syntax

exist name
exist name searchType
A = exist(___)

Description

example

exist name returns the type of name as a number. This list describes the type associated with each value:

  • 0 — name does not exist.

  • 1 — name is a variable in the workspace.

  • 2 — name is a file with extension .m.mlx, or .mlapp, or name is the name of a file with a non-registered file extension (.mat.fig.txt).

  • 3 — name is a MEX-file on your MATLAB® search path.

  • 4 — name is a Simulink® model or library file on your MATLAB search path.

  • 5 — name is a built-in MATLAB function. This does not include classes.

  • 6 — name is a P-code file on your MATLAB search path.

  • 7 — name is a folder.

  • 8 — name is a class. (exist returns 0 for Java classes if you start MATLAB with the -nojvm option.)

MATLAB searches starting at the top of the search path, and moving down until a result is found or the last folder on the path is reached. If more than one name exists in a folder, MATLAB displays the first instance of name, according to the Function Precedence Order. Folders are an exception to the function precedence rules. They have precedence over all types except for variables.

For example, if name matches both a file with a .m extension and a P-code file, then exist returns 6, identifying it as a P-code file. If name matches both a variable and a P-code file, exists returns 1, identifying it as a variable. If name matches both a folder and a MATLAB function, exist returns 7, identifying it as a folder.

example

exist name searchType returns the type of name, restricting results to the specified type, searchType. If name of type searchType does not exist, MATLAB returns 0.

example

A = exist(___) returns the type of name to A.

Examples

collapse all

Check Existence of Workspace Variable

Create a variable named testresults, and then confirm its existence in the workspace.

testresults = magic(5);
exist testresults
ans = 1

A variable named testresults exists in the workspace.

Check Existence of Folder

Create the folder myfolder, and then check its existence as a folder.

mkdir myfolder;
exist myfolder dir
ans = 7

If you specify the type as file, MATLAB® searches for both files and folders, therefore returning the same result.

exist myfolder file
ans = 7

Check if MATLAB Function is Built-In Function

Check whether the plot function is a built-in function or a file.

A = exist('plot')
A = 5

This indicates that plot is a built-in MATLAB function.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值