I’ve looked up previous answers to this question but haven’t found a suitable answer.
I am trying to Map a function that I defined across a Matrix. The function Maps fine across a 1D array but can’t figure out the syntax to make it work across a matrix.
As an example, I have the following functions defined…
allanVar[ylist_, n_] := 1/2 Mean[(ListCorrelate[Append[PadRight[{-1}, n], 1], MovingAverage[ylist, n]])^2]
clusters[Npts_] := Union[ Table [Round[10^((i - 1) Log[10, 1000]/Npts)], {i, 1, Npts + 1}]]
allanData[zlist2_, Npts_] := Transpose[{clusters[Npts], 3600*Sqrt[allanVar[zlist2, #]] & /@ clusters[Npts]}];
I create some sample random data in Matrix form
data = Table[0, {3000}, {5}];
Do[data[[All, i]] = RandomVariate[NormalDistribution[0, 0.1], 3000] +
RandomFunction[WienerProcess[0.005, 0.01], {1/100, 30, 1/100},
5]["Path", i][[All, 2]] ; , {i, 1, 5} ];
I can Map the function allanData to one of columns of my matrix just fine…
ListLogLogPlot[allanData[data[[All, 1]], 20], Joined -> True]
But trying to map it to the entire matrix gives me Tensor order errors… not quite sure how to make the functions map across the matrix….
ListLogLogPlot[allanData[data, 20]]
ListLogLogPlot[allanData[#, 20] & /@ Transpose[data]]? – Michael E2 Mar 14 at 16:24Mapyet? Investigate its optional third levelspec argument. – whuber Mar 14 at 16:24levelspecfor Map…. – Pam Mar 14 at 16:28