以下代码无缝执行
wave = HaarWavelet[];
type = "PrimalLowpass";
h = WaveletFilterCoefficients[
wave, type,
WorkingPrecision -> \[Infinity]
];
h = Flatten[
Take[h,
Range[1, Length[h]],
Table[2, {Length[h]}]
]
]
但是当用Module
包裹它时,有些错误。考虑函数
getWaveletFilter[wave_, type_]:=
Module[{filter}, (* treated as local *)
filter = WaveletFilterCoefficients[
wave, type, WorkingPrecision -> \[Infinity]
]
filter = Flatten[
Take[filter,
Range[1, Length[filter]],
Table[2, {Length[filter]}]
]
]
filter
]
我想getWaveletFilter[HaarWavelet[], "PrimalHighpass"]
返回
{1/2, -1/2}
相反,Mathematica有各种各样的抱怨。有什么建议吗?
答案 0 :(得分:6)
您需要在模块中的每个操作之间放置一个分号以将它们分开:
getWaveletFilter[wave_, type_]:=
Module[{filter}, (* treated as local *)
filter = WaveletFilterCoefficients[
wave, type, WorkingPrecision -> \[Infinity]
];
filter = Flatten[
Take[filter,
Range[1, Length[filter]],
Table[2, {Length[filter]}]
]
];
filter
]
阅读CompoundExpression (;)以便更好地理解。