fprintf repetition

10 次查看(过去 30 天)
Ammar
Ammar 2011-10-24
Hello,
I have to create a table using fprintf and the first two lines look like this:
Physical Temperature T (F) | 40 35 30 25 20 15 10 5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45
The first character in the second line is an absolute value line (not sure what it is really called).
T=[40:-5:-45]
When I try to print the second line, I use
fprintf('| %3d',T)
but that keeps giving me the absolute value sign before every value of T.
How can I keep the absolute value sign from repeating itself?
Thanks

采纳的回答

Walter Roberson
Walter Roberson 2011-10-24
Answer: Don't Do That.
fprintf() the absolute value sign in one operation, and then fprintf() the numbers in a second operation.
Or, repeat the ' %3d' part in the format as many times as you have numbers to print. Such as
fprintf('| %3d %3d %3d %3d %3d\n', T)
if you were printing out 5 numbers across.
  1 个评论
Ammar
Ammar 2011-10-24
Thank you so much. I didn't even realize that I could break the text into different sections. It worked perfectly.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by