Unexpected behavior of mean function

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?

Respuestas (1)

Stephen23
Stephen23 el 5 de Feb. de 2020
Editada: Stephen23 el 5 de Feb. de 2020
"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...

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Feb. de 2020

Editada:

el 5 de Feb. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by