Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no method matching setindex : trying to change matrix values

Tags:

julia

Using Julia, I've defined a 9x10 matrix of zeros, and am trying to change a single entry , but I get the error 'setindex!' has no method matching setindex!(::Float64, ::Float64, ::Int64)

My code is:

m = zeros(9,10)
m[1][1] = 1.0

with the error pointing to the second line. typeof(m) is an Array{Float64,2}, which, as far as I can tell is mutable.

What am I doing wrong here?

like image 487
masher Avatar asked Sep 26 '15 13:09

masher


1 Answers

To index 2-dimensional arrays, just use m[1,1].

The syntax m[1][1] would be valid for a 1-dimensional array of 1-dimensional arrays.

m = zeros(9,10)
m[1,1] = 1.0

m = Array[ [1,2], [3,4,5] ]
m[1][1]
like image 116
Vincent Zoonekynd Avatar answered Nov 30 '22 11:11

Vincent Zoonekynd