0

Please, tell me what is the issue with the following code?

Dimensions[Subscript[R, 2]]
{201, 161, 53}
Table[
  If[Subscript[R, 2][[x, y, z]] != 2, Subscript[R, 2 ][[x, y, z]] = 0], 
  {x, 1, 201}, {y, 1, 161}, {z, 1, 53}];

I am getting this error:

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
phdstudent
  • 423
  • 3
  • 12

1 Answers1

3

What you see here is the direct result of ignoring advice:

Don't use subscripted variables if you don't know the concequences!

What happens is that you think you assign your array to a variable R... you don't! Basic example

Subscript[a, 1] = {1, 2, 3}

(* {1, 2, 3} *)

Now try ?a and if this doesn't work, try to find where your list is stored. Right, it is stored as DownValues for Subscript:

DownValues[Subscript]

(* {HoldPattern[Subscript[a, 1]] :> {1, 2, 3}} *)

Unfortunately, the assignment operator for list elements aka

l[[n]] = blub

does not work here. Therefore, use simple symbols and you are fine.

halirutan
  • 112,764
  • 7
  • 263
  • 474