5
$\begingroup$

I want to "map" an argument to a list of functions.

Here is the concrete Problem. I generate a list "Messungfit" of functions:

Messungfit = Table[LinearModelFit[Messungenplot[[i]], {1, x}, x], {i, NM}];

Now I want to get some more Information from one fit:

Messung[[1]]["ParameterTable"]

This works perfectly fine. But what if I want to do this for the whole list. That means Passing the Argument to each function. I tried something like:

Messungfit["ParameterTable"]

This does not work.

$\endgroup$
  • 4
    $\begingroup$ See Through. $\endgroup$ – ilian May 19 '15 at 21:57
  • $\begingroup$ Try #["ParameterTable"]&/@Messungfit? $\endgroup$ – kglr May 19 '15 at 22:03
  • $\begingroup$ Thank you very much. The second one works perfectly. But Through does not work. Through[Messungfit, ["ParameterTable"]] $\endgroup$ – mcocdawc May 19 '15 at 22:07
  • $\begingroup$ @mcocdawc, both should work. You need to use: Through[Messungfit["ParameterTable"]] or Through@Messungfit@"ParameterTable" $\endgroup$ – kglr May 19 '15 at 22:22
  • $\begingroup$ Thank you very much. I am quite a beginner. $\endgroup$ – mcocdawc May 19 '15 at 22:22
4
$\begingroup$

As mentioned by kglr and ilian in the comments, you can do one of two things. We can define a function that you can map over the function, i.e.

#["ParameterTable"] &

is the pure function that will accept the Head of a function, and we map this over the list of function as

#["ParameterTable"] & /@ Messungfit

Alternatively, we can use Through, which is designed to do what the OP is asking, essentially. The correct syntax is

Through[Messungfit["ParameterTable"]]

or

Through @ Messungfit @ "ParameterTable"
$\endgroup$

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.