Function "fix" with numbers/characters

7 visualizaciones (últimos 30 días)
sangho bok
sangho bok el 13 de En. de 2017
Editada: Stephen23 el 14 de En. de 2017
I used a function, fix, in a way which was not supposed to be used as below. fix 5.4 instead of fix(5.4)
fix 5.4 gives "53 46 52" which is in ASC II. If I use other functions like round, etc. these acted the same way. I just wonder why it happened and what it is doing.
Thank you.

Respuestas (2)

James Tursa
James Tursa el 13 de En. de 2017
Editada: James Tursa el 13 de En. de 2017
When you invoke a function without using the parentheses, MATLAB regards all of the inputs as strings. This is true for any function, not just fix. Note that when you entered the function without parentheses, the arguments are shown in purple font ... your clue that these are regarded as strings.
fix 5.4 <-- The 5.4 appears in purple font
is the same as
fix('5.4') <-- The '5.4' appears in purple font

Stephen23
Stephen23 el 14 de En. de 2017
Editada: Stephen23 el 14 de En. de 2017
Command syntax (all words are strings, each space separates input arguments):
fix 5.4
is equivalent to writing this:
fix('5.4')
Function syntax (inputs are interpreted as their native type):
fix(5.4)
These are two totally different things, as is explained here:

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by