0

I am writing an output file to MATLAB as part of a report. I need to center justify the title which is having a fixed column width.

If I use the below code it becomes right-justified.

fprintf(fileID,'%50s \r\n', 'Balance Sheet')

And if I use the below code it becomes left-justified.

fprintf(fileID,'%-50s \r\n', 'Balance Sheet')

But how do I center-justify?

naseefo
  • 720
  • 1
  • 9
  • 30
  • Thank you Steve. Yes, this helps but I was wondering if there is more direct command as I believe this ought to be of a standard use for which an option might be available in the library. – naseefo Mar 26 '17 at 21:25
  • Not aware of one, but if you know what the maximum width should be (50 here?) then it should be pretty straightforward to write your own function with `length()` – Steve Mar 26 '17 at 21:27
  • 3
    See: [`strjust`](https://www.mathworks.com/help/matlab/ref/strjust.html) – sco1 Mar 26 '17 at 21:28
  • strjust is only applied with in a cell in MATLAB – naseefo Mar 26 '17 at 23:04
  • That's [not true](https://www.mathworks.com/help/matlab/ref/strjust.html#inputarg_txt). – sco1 Mar 27 '17 at 00:59

0 Answers0