Function converts numbers from command line to ASCII value

Hey guys,
I have a Problem with my input. As soon as I input a number into any functio e.g. 0 it is convertet to the value 48.
This means if I want to run this function on the number 0:
function test(x)
fprintf ('Value: %2.2d \n', x)
end
If I was to enter test 0 into my command line the answer would be 48
And long numbers become just a vector of their ASCII values. Anybody got a clue to why this happens?

 Respuesta aceptada

You're calling your function in command form.
test 12345
This is equivalent to the following function form:
test('12345')
See this documentation page for more information about command and function form. If you want to pass the number 12345 into test, call it using function form.
test(12345)

1 comentario

Thank you kind Sir this helps a lot. Silly how such a simple thing can drive you crazy...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Mayo de 2019

Comentada:

el 9 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by