I need to write into multiple files in a Do
loop.
Hence, I tried to open multiple streams:
Do[ Symbol[StringJoin["S", ToString[i]] ] =
OpenAppend[StringJoin["sf", ToString[i]],
FormatType -> OutputForm ], {i, 1, 10}]
But this gives errors like:
Set::write: Tag Symbol in Symbol[S1] is Protected. Set::write: Tag Symbol in Symbol[S2] is Protected.
What is the correct way to name the indexed output streams in a Do
loop ?
Attributes[Set]
, it includesHoldFirst
, so the left hand side of=
(Set
) is held. $\endgroup$Subscript
while defining symbols (variables).Subscript[x, 1]
is not a symbol, but a composite expression whereSubscript
is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doingSet[Subscript[x, 1], 2]
which is to assign a Downvalue to the opratorSubscript
and not an Ownvalue to an indexedx
as you may intend. Read how to properly define indexed variables here $\endgroup$