how can I print the plus automatically when using sprintf?
5 次查看(过去 30 天)
显示 更早的评论
I have noticed that when using sprintf the plus is not displayed, can anyone help me find a solution? i just need to print the valueswiththe relative sign.
sprintf('(x%g)(x%g)(x%g)(x%g)(x%g)(x%g)',x1,x2,x3,x4,x5,x6)
Thank you in advance
0 个评论
采纳的回答
Guillaume
2019-8-22
Read the documentation of the formatspec of any of the *printf function. It's explained right there under Flags:
'+' Always print a sign character (+ or –) for any numeric value.
so:
>> sprintf('x(%+g)', 5.2)
ans =
'x(+5.2)'
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!