MATLAB: Using text, 2 variables, and decimals in fprintf

fprintf

fprintf(["The value you entered "+'%.1f°C\n',temp + "is equal to "+'%.1f°F\n',ans])
Can someone help me make this line work. I feel like I'm close but I keep getting errors.

Best Answer

Try this:
fprintf("The value you entered %.1f°C\nis equal to %.1f°F\n", temp, ans)
so:
temp = 10;
ans = 50;
fprintf("The value you entered %.1f°C\nis equal to %.1f°F\n", temp, ans)
produces:
The value you entered 10.0°C
is equal to 50.0°F
To get it all on one line, replace the first ‘\n’ with a space:
fprintf("The value you entered %.1f°C is equal to %.1f°F\n", temp, ans)
producing:
The value you entered 10.0°C is equal to 50.0°F
.