2
$\begingroup$

I noticed there are a few similar questions to mine on here, but I couldn't figure out how to accomplish this mapping.

I have sets of data I want to plot, which represent intensity and frames, and I need to convert all of the x data into time, using the frame rate. To do this I have defined 2 functions

frame2Time[frame_, framerate_] := frame/framerate;
transform2Time[lst_, framerate_] := lst /. {x_, y_} :> {frame2Time[x, framerate], y}

Then I have three trials for each experiment. set1 is trial 1 etc.... It is possible that there are not the same number of trials for each experiment. This is simulated by set2 only have two {x,y} pairs.

set1 = {{1, 1}, {2, 2}, {3, 3}}
set2 = {{1, 11}, {2, 22}}
set3 = {{1, 111}, {2, 222}, {3, 333}}

here each lst is each experiment I conducted.

lst1 = {set1, set2, set3}
lst2 = 10*lst1
lst3 = 100*lst1

Now I want to apply the transform2Time to each each trial of each experiment

ulttst = Map[transform2Time[# , 10] , {2}]  & /@ {lst1, lst2, lst3} // N

However this mapping does not work. I get an a weird [2] embedded in my list that I cannot get rid of.

$\endgroup$
3
$\begingroup$

Your current syntax is trying to Map the function {2} onto each element in the list generated

transform2Time[#,10] &/@ {lst2,lst2,lst3}

I think this is what you want?

ulttst = N@Map[transform2Time[#, 10] &, {lst1, lst2, lst3}, {3}]
$\endgroup$
  • $\begingroup$ Correct, elegant and terse. What more could one ask for? $\endgroup$ – Jack LaVigne Jul 10 '15 at 20:55

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.