I am having a very strange issue with global variables in Matlab.
Usually, when you declare a variable to be global before assigning any value to it, it will be left as an empty variable. I have a variable R which I want to declare as global. But after I type clear and global R, in the variable list R is already set to be a 1*18 array, with some zero’s and other numbers filled in it.
I do have some other functions and scripts which share the global variable R, but I made sure I did not call any of the scripts or functions after I typed clear, and the variable list is already empty when I typed global R from the prompt.

But still, the problem persists. I guess I must have some serious misunderstanding of the rules about global variables. Can anybody explain why this is happening?
Thanks in advance.
The
clearcommand does not clear global variables. It removes the variable from your local workspace, but it is still there. So if you assigned some value to it previously, declaring it again simply ‘shows’ the global variable in your local scope. You have to useclear allorclear global. From the documentation ofclear:Consider the following example: