Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to get a function to print stuff with REPL-like formatting

$
0
0

Sometimes it’s easier if what gets printed by a function looks nice (like in the REPL):

function printout(x)
    println("x is: ",x)
end

Ex 1. Beautiful formatting that can be instantly read and understood:

check = rand(2,10)
2×10 Array{Float64,2}:
 0.20608   0.675941  0.267637  0.231587  0.404712  0.628064  0.727315  0.292798  0.579271  0.00830696
 0.570077  0.440174  0.997781  0.842532  0.752924  0.360579  0.368976  0.264956  0.20852   0.166019

Ex. 2. Printing from inside a function: the first semi-colon is somewhere in there…

printout(check)
x is: [0.20607999980294323 0.6759405043446565 0.2676368465413639 0.23158728513903615 0.40471156297506106 
0.6280638109428014 0.7273151713873742 0.2927977847045118 0.5792709021856115 0.008306955592047194; 0.5700766059127313 0.4401739651076826 
0.9977809895843064 0.8425324418892446 0.7529240018391419 0.360578553537942 0.3689764314494348 0.26495555789141423 0.20851971242325895 0.1660188215790821]

How can I make printout() give me output like Ex. 1?

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images