clear Arduino as a global variable in Matlab I'm trying to use Arduino in Matlab. cause I used Arduino in some function I had to define Arduino as a global variable. 

clc,clear,close all;
global a
a = arduino();
.
some functions
.
clear a


at the end of my code I clear the variable but as I run the code again this error appear:

Failed to open serial port (user COM) to communicate with board Uno. ...
 Make sure there is no other MATLAB arduino object for this board.


I guess the global function can't be clear by clear command so I tried clear all instead clear in the last line. It works perfect as I run it again and again but as you know this is Matlab tips for clear all command

Using clear all causes MATLAB® to recompile previously cached code, 
and can decrease performance.


I've tried delete(a) so the result was: 

Error using arduino/delete
Cannot access method 'delete' in class 'arduino'.


any help would be appreciated.
In the MatLab Help Center they had nice description of how to clear a variable from memory. Check it here: https://www.mathworks.com/help/matlab/ref/clearvars.html 

In your case should be: clearvars -global a;