How to change the matrix output format?

This is how I want it to look

And this is how it currently looks

What is the output of

my_format = format ()

in your Octave session?

It looks like you are using format free:

>> A = full (sprand (5, 5, 0.5));
>> format free
>> A
A =

 0 0.952158 0.261092 0.210641 0
 0 0.988495 0.0746316 0 0.142534
 0.134892 0.0478216 0.839058 0 0
 0 0 0 0 0.28438
 0.257299 0 0.429129 0 0.617212

>> format short
>> A
A =

        0   0.9522   0.2611   0.2106        0
        0   0.9885   0.0746        0   0.1425
   0.1349   0.0478   0.8391        0        0
        0        0        0        0   0.2844
   0.2573        0   0.4291        0   0.6172