masher
masher

Reputation: 4096

no method matching setindex : trying to change matrix values

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?

Upvotes: 9

Views: 10440

Answers (1)

Vincent Zoonekynd
Vincent Zoonekynd

Reputation: 32351

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]

Upvotes: 14

Related Questions