fprintf curiosity about incorrect value returned when string is assigned as a number.
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!