# Automatically generate and manipulate variables in Mathematica

First line is just loading data from a txt.file, so that i get two lists {f1,f2,f3,..},{laser1,laser2,laser3,..}.

How can I do the same thing as above in just one line? i.e. I have a list of laser measurement points, I get every ith element. There are total 11 columns corresponding to different powers. I imagine there must be a neat and efficient way to deal with much larger set of data analysis. If above is possible, then it must be possible to manipulate these automatically generated variables. E.g. How can one use this assigned variable LaserOnIQ_i, such that LaserOnIQ_i can be manipulated in a for loop, where i is just an assigned number.

I want to plot all the graphs for LaserOnIQ_1 to IQ_11. I would try to write something like (which obviously doesn't work) [For i=1, i>1, i++, PlotIQ_i=ListLinePlot[{LaserOnF*10^-9, Abs[LaserOnIQ_i]}[Transpose], ] i.e. i loop from i=1 to i=11...

So that after this loop is finished, I just type PlotIQ_1, and I can easily retreive the plot I wanted.

By contrast, the main idea is that I would like to manipulate data variables just as numbers ... i.e. [i=1,i<100,i++, i=i*2] But I don't think you can easily do it with user created variables...

• Look up Partition[] and Transpose[]. – J. M. will be back soon May 7 '16 at 7:11
• You can use something like laserOnIQ[i] = ... – Marius Ladegård Meyer May 7 '16 at 8:09
• Please see below for a better solution! – el psy Congroo May 8 '16 at 17:36

LaserOnIQ = RandomReal[1, 5511];

Do[
ToExpression[
"LaserOnIQ" <> ToString[i], StandardForm,
Function[sym, sym = LaserOnIQ[[i ;; 5511 ;; 11]], HoldAll]
],
{i, 1, 11}
]


Now you have 11 variables LaserOnIQ_i.

LaserOnIQ1 // Short


{0.677306,0.0902459,<<498>>,0.301712}

Do[
ToExpression[
"PlotIQ" <> ToString[i], StandardForm,
Function[sym,
sym = ListLinePlot[ToExpression["LaserOnIQ" <> ToString[i]]],
HoldAll]
],
{i, 1, 11}
]


Now you have 11 plots PlotIQ_i.

PlotIQ1


• Excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!! – el psy Congroo May 8 '16 at 17:35
• Alexey, is there any way to call all the plots at once using a loop? I tried writing something like Do[ToExpression["PlotAllArg", StandardForm, Function[sym, sym = Show["PlotIQArg" <> ToString[i]], HoldAll]], {i, 1,100}]. But it doesns't work.. – el psy Congroo May 11 '16 at 10:55
• @elpsyCongroo, Do[Print@ToExpression["PlotIQ" <> ToString[i]], {i, 1, 11}] – Alexey Golyshev May 11 '16 at 13:33