Unexpected behavior of mean function
Ältere Kommentare anzeigen
I did the following:
X = [1;2;3;4;5];
mean X %I know, I forgot the parens - so I expected an error
%Here's what I got
ans = 88 % The ASCII code for 'X'
%Can anyone tell me why I got this answer?
Antworten (1)
"Can anyone tell me why I got this answer?"
You called the command syntax of mean:
As that documentation explains, these two are equivalent:
mean X
mean('X')
Although it can be convenient at the command line, I strongly recommend avoiding the command syntax in code. The command syntax is a momento of MATLAB's venerable age, from the dark-ages when programming languages commonly did such things...
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!