In Mathematica 9, I had the function(s). I apologize for the weak formatting.
RemoveBackground[data_,n_,rng_?NumericQ]:=RemoveBackground[data,n,{{-∞,-rng},{rng,∞}}];
RemoveBackground[data_,n_:2,regions_:{{-∞,∞}}]:= (
RemoveBackground[] = Function[{x}, Evaluate[
Fit[
(* select points only in specified regions *)
Select[
Flatten[data,Depth[data]-3],
Function[{pt},Or@@(#[[1]]<=pt[[1]]<=#[[2]]&/@regions)]
][[;;,;;2]],
(* build list of polynomial terms *)
x^#&/@Range[0,n],
x
]
]];
Map[ReplacePart[#,2->#[[2]]-RemoveBackground[][#[[1]]]]&, data, {-2}] );
Now in Mathematica 10.0, RemoveBackground
is a protected function. I know that you can unprotect variables. This worked perfectly fine when I had to do it Devices
, which they also protected in Mathematica 10.0. For some reason since one of the calls to RemoveBackground
has four arguments it goes red inside the package and continues to give the message
SetDelayed::write: Tag RemoveBackground in RemoveBackground[data_, n_:2, regions_:{{-inf,inf}}] is protected.
It doesn't seem to to matter where I put Unprotect[RemoveBackground]
; I keep getting this error. Any ideas as to why?
I have also tried various combinations of Unprotect
then Clear
as well.
RemoveBackground
is a new system function. You'll need to change the name of yours. See reference.wolfram.com/language/ref/RemoveBackground.html $\endgroup$System`
symbol to make way for yours, because you never know what depends internally on what (and it is a bad practice, period.) and you could be doing more damage than you think. Rather, you might want to look at using the full contexts, such asMyPackage`MySymbol
andSystem`MySymbol
. This way, you get to use both functions. You can also change the order in which the contexts appear in$ContextPath
to determine which definition is used first. $\endgroup$