# 检查一个变量是否存在于工作区 MATLAB 中

`exist` 函数给出从 `0 到 9` 的数字。每个数字都有其含义，具体取决于我们搜索的变量。

## 在不使用 MATLAB 中的任何内置函数的情况下检查工作区中观察下的变量

``````a = 1;
b = 1;
c = 1;
d = 1;
check_workspace_variables('d')
check_workspace_variables('b')
check_workspace_variables('c')
check_workspace_variables('e')
functionour_output =check_workspace_variables(variable_check)% Check to see if a variable exists in the Base Workspace
does_string_exists = sprintf('exist(''%s'')',variable_check);
our_workspace_variables = evalin('base',does_string_exists);
if our_workspace_variables == 1 % If variable exists in our workspace in MATLAB
disp('Is Present in our Workspace')
our_output = 1 ;
else % If variable doesnot exist in our workspace in MATLAB
disp('Is Absent from our Workspace')
our_output = 0 ;
end
end
``````

``````check_variable_presence
Is Present in our Workspace
ans = 1
Is Present in our Workspace
ans = 1
Is Present in our Workspace
ans = 1
Is Absent from our Workspace
ans = 0
``````

## 使用 MATLAB 中的 `Exist` 函数检查工作区中观察下的变量

``````our_variable = magic(5)
exist our_variable
``````

``````our_variable =
17    24     1     8    15
23     5     7    14    16
4     6    13    20    22
10    12    19    21     3
11    18    25     2     9
ans = 1
``````
{"ft_lang_label":"__label__zh","ft_lang_prob":0.7486901,"math_prob":0.93801683,"size":1721,"snap":"2023-40-2023-50","text_gpt3_token_len":868,"char_repetition_ratio":0.20151427,"word_repetition_ratio":0.11737089,"special_character_ratio":0.25217897,"punctuation_ratio":0.04032258,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98661387,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-11-30T07:25:20Z\",\"WARC-Record-ID\":\"<urn:uuid:d17b3e21-2330-4b95-a6ab-f73e27894451>\",\"Content-Length\":\"89073\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2c1f3178-4bf0-4ce0-86e4-7317be931f49>\",\"WARC-Concurrent-To\":\"<urn:uuid:e5344ed1-6951-45f0-bcaf-08d706bdac87>\",\"WARC-IP-Address\":\"8.45.176.232\",\"WARC-Target-URI\":\"https://www.zadmei.com/jcygblsf.html\",\"WARC-Payload-Digest\":\"sha1:HQFDPZ24PW7B5RE7LLZ4QGX7NLI3U4DH\",\"WARC-Block-Digest\":\"sha1:KRWUGPJP7IIHYOL53TJTJFGVHARHWKBX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100172.28_warc_CC-MAIN-20231130062948-20231130092948-00608.warc.gz\"}"}