I want to assign a value to one location in an existing matrix, but I get an error.
The desired result is {{1, 2, -3}, {3, -1, 6}}. Can someone please help?
I want to assign a value to one location in an existing matrix, but I get an error.
The desired result is {{1, 2, -3}, {3, -1, 6}}. Can someone please help?
You need to use the unnested form e.g. m[[2,1]]=3. As an rvalue (in the CS sense) m[[2]][[1]] is fine, but it does not work as an lvalue (that is, something to which one can assign a value) in Mathematica.
Awesome! Thank you. I know this seems really basic, but stuff like this really slows things down.
This is strange; the code above works perfectly on my machines (Win7 / MMA9) and (Linux / MMA10):
In[1]:= m = {{1, 2, -3}, {0, -1, -6}}
m[[2]][[1]]
m[[2]][[1]] = 3
m
Out[1]= {{1, 2, -3}, {0, -1, -6}}
Out[2]= 0
Out[3]= 3
Out[4]= {{1, 2, -3}, {3, -1, -6}}
@Daniel Lichtblau: Thank you for pointing out the principal difference in the notation [[n,m]] and [[n]][[m]]! Once one knows it, it becomes quite obvious ā¦
I stand corrected. Apparently that did work as an lvalue. Iām thoroughly confused now. But corrected. (Better than being certain and wrong though.)