How do you left or right justify matrix columns?

I have search through every help topic I could think of, and still can't find the commands to right or left justify the columns in a matrix. Can anyone help me?

 Accepted Answer

fliplr()

2 Comments

Thanks, but I do not want to flip the rows. I want to right justify, or left justify the columns of a matrix in the command window.
upload a sample of your desired output so that it‘s clear what you eactly mean , suspect you should be using fprintf() or sprintf()

Sign in to comment.

More Answers (1)

There is no MATLAB command to left or right justify command window output. If you want left or right justified command window output then you need to format the data as characters and display the characters. fprintf() could be used.
In particular for fprintf() and sprintf() when you use a field width (a number between the '%' and the '.' in the format specification) then by default the output is right justified within that width; however a negative number indicates left justification.
For example,
fprintf('XXXXX%10.3fXXXXX%-10.3fXXXXX\n', 3.14, 3.14);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!