fprintf curiosity about incorrect value returned when string is assigned as a number.
Afficher commentaires plus anciens
Hello,
I am learning about fprintf and I was playing around. I ended up with this string below. I realize now that in the second sentence it should be %s because it's printing a string.
But! Here's my question. I don't get returned an error message. Instead, I get that 10 + 34 is 52.
WHY? I want to know.
N = 10; S = 34;
fprintf('What is %g plus %g? It''s %g! \n', N , S, num2str(N + S))
When I use fprintf('What is %g plus %g? It''s %s! \n', N , S, num2str(N + S)) I get 44 as expected.
Can anyone tell me why 52 is the number returned when the string is commanded as a number?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!