Trouble Formatting fprintf Table
显示 更早的评论
I'm trying to make a simple table with 4 rows, 2 columns, and 2 headers. I can't quite seem to figure out how to edit it so that it's correct. Here's what I have so far:
T= [-10 0.0 10 20];
V= [0.0 5.0 10.0 15.0];
fprintf('Temperature (C): \t Voltage (volts):\n)%2.0f %2.0fT',[T,V].')
And here is the output:
Temperature (C): Voltage (volts):
)-10 0TTemperature (C): Voltage (volts):
)10 20TTemperature (C): Voltage (volts):
) 0 5TTemperature (C): Voltage (volts):
)10 15T>>
回答(1 个)
dpb
2013-9-5
Put the position of the numeric fields in wrong place...
>> fprintf('Temperature (C): %3.0f Voltage (volts): %2.0f \n',[T,V]')
Temperature (C): -10 Voltage (volts): 0
Temperature (C): 10 Voltage (volts): 20
Temperature (C): 0 Voltage (volts): 5
Temperature (C): 10 Voltage (volts): 15
>>
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!