11

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?

Stewie Griffin
  • 14,159
  • 11
  • 36
  • 66
hmi2015
  • 741
  • 2
  • 8
  • 21
  • 2
    Possible duplicate of [read into arrays in Julia](http://stackoverflow.com/questions/24295276/read-into-arrays-in-julia) – dasdingonesin Feb 10 '16 at 08:05

1 Answers1

19
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
daycaster
  • 2,365
  • 2
  • 12
  • 16