MATLAB: With and without bracket

bracket

SD = [1 2 3 4 5 6 7 8 9 10], I want to calculate the mean of SD, the two codes below gives me two answers
why bracket can make difference.
1) mean SD
2) mean (SD)

Best Answer

This statement calls the mean function using command syntax.
mean SD
This is equivalent to the following:
mean('SD')
mean(double('SD'))
mean([83 68]) % ASCII values of 'S' and 'D'
On the other hand, this statement calls the mean function using function syntax, with the variable whose name is SD as the input rather than the char array 'SD' as input.
mean(SD)
For more information about the difference between command syntax (most commonly used for functions like help, doc, hold, etc.) and function syntax see this post on Loren's blog and/or this page in the documentation.
Related Question