Reading data matrix from text file in Julia

hmi2015 picture hmi2015 · Feb 10, 2016 · Viewed 7.8k times · Source

I have text file which includes a matrix. I want to read it in julia as a matrix.

The text file is like:

0 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 1
1 0 0 0 1 1 0

In matlab you can do the following to create matrix M :

file='name.txt';
[M] = load(file);

How to do same thing in Julia?

Answer

daycaster picture daycaster · Feb 10, 2016
shell> cat /tmp/m.txt
0   0   0   0   0   0   0
1   0   0   0   0   0   0
1   0   0   0   0   0   1
1   0   0   0   1   1   0

julia> m = readdlm("/tmp/m.txt")
4x7 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0
 1.0  0.0  0.0  0.0  0.0  0.0  0.0
 1.0  0.0  0.0  0.0  0.0  0.0  1.0
 1.0  0.0  0.0  0.0  1.0  1.0  0.0