Hi I'm absolutely newbie in Mathematica and have following problem:
My list looks like {{50, 0.75}, {51, 0.76}, ...
, and I want to choose a range out of my x-values (I don't want so say: from point 150 to ..., I want to choose with values like from x value 50 to 60), with only these points a linear regression has to be done.
I tried with LinearModelFit[data, x, x]
, and Mathematica made a linear regression with all values, now I want to choose a range but I can't find a solution =(
Has somebody an idea?
Answer
As suggested by @b.gatessucks you can use Select
.
data = Table[{x, Sin[x] + RandomReal[{-0.5, 0.5}]}, {x, 0, 15, 0.25}];
pl = ListPlot[data];
ff = LinearModelFit[data, Sin[x], x]
Show[pl, Plot[ff[x], {x, 0, 15}]];
and after selection over the range [2,8]:
ff2 = LinearModelFit[Select[data, #[[1]] > 2 && #[[1]] < 8 &], Sin[x], x]
Show[pl, Plot[{ff[x],ff2[x]}, {x, 0, 15}]];
Comments
Post a Comment