Help with printing output
Show older comments
I was trying to print some output that looks like this
Hours Linear Interpolation Nearest Interpolation
13.00 74.52 77.40
22.00 30.02 36.30
41.00 22.68 22.00
...and this is my coding...
disp(' Hours Linear Interpolation Nearest Interpolation')
fprintf(' %.2f %.2f %.2f\n', hours2(1), x(1), y(1))
fprintf(' %.2f %.2f %.2f\n', hours2(2), x(2), y(2))
fprintf(' %.2f %.2f %.2f', hours2(3), x(3), y(3)
I got the output that I want, but is there a way to make the coding looks more beautiful? and I also needed to add space manually to the data(value) so that it alligns with its column in which I thinks that it is kinda ineffecient.
Accepted Answer
More Answers (1)
madhan ravi
on 2 Jun 2020
fprintf(' %.2f %.2f %.2f\n', [hours2(:).'; x(:).'; y(:).']) % Look documentation for adding space notation
1 Comment
Nazarudin Iqzuan Marzulino
on 2 Jun 2020
Categories
Find more on Logical 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!