0
$\begingroup$

I make a list of 5 empty $3 \times 3$ matrices via

 Table[m[i]=IdentityMatrix[3]-IdentityMatrix[3],{i,1,5}]

However when I want to change an entry via

 m[2][[3,4]]=5

I get an error which reads:

Set::setps: m[2] in the part assignment is not a symbol. >>

Any ideas? Thanks

$\endgroup$
  • 2
    $\begingroup$ Why not do something like m = ConstantArray[0, {5, 3, 3}] and then do m[[2, 3, 4]] = 1? $\endgroup$ – J. M. is away Mar 30 '17 at 5:37
  • $\begingroup$ You mean instead of explicitly indexing the matrices, placing them in a list and identifying them there. That does make the way I call the matrices a little more intuitive, I don't have the single brackets and then the double brackets. However, I'm curious why indexing the matrices directly messes with the assignment I make. $\endgroup$ – Mike Mar 30 '17 at 5:40
  • 1
    $\begingroup$ The docs for the error message just says "Part assignments are implemented only for parts of the value of a symbol." So since m[2] is not a symbol itself, but a reference to one of the DownValues of the symbol m, this is what you get. $\endgroup$ – Marius Ladegård Meyer Mar 30 '17 at 5:42
  • $\begingroup$ Also, note the difference between Do and Table, we don't use Table just for side effects ;) $\endgroup$ – Marius Ladegård Meyer Mar 30 '17 at 5:43
  • 2
    $\begingroup$ You can do e.g. m[2] = ReplacePart[m[2], {3, 4} -> 5] but that copies the whole of m[2] so I would prefer @J.M. 's suggestion. $\endgroup$ – Marius Ladegård Meyer Mar 30 '17 at 5:49
2
$\begingroup$

As the comments read, the problem is that m[2] is not a symbol but a reference to a value of the symbol m, so to change the value there I have to actually replace it via:

 m[2]=ReplacePart[m[2],{4,5}->5].

Which copies the entirety of m[2] and doesn't look all that pretty.

J.M.'s suggestion is to just make a list of the matrices and refer to them from there.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.