designFilt error ONLY inside function "Incorrect dimensions for matrix multiplication"

I'm using designFilt to make a simple bandpass filter for some data before doing further analysis:
myfilt = designfilt('bandpassfir','FilterOrder',20, 'CutoffFrequency1',0.1,'CutoffFrequency2',7, 'SampleRate',128);
If I run this line directly in the command window, it works just fine. (In my old scripts it worked fine too.) However, when I call it from inside a function embedded in a larger script, I get this error:
Error using designfilt>parseAndDesignFilter (line 516)
Incorrect dimensions for matrix multiplication. Check that
the number of columns in the first matrix matches the number
of rows in the second matrix. To perform elementwise
multiplication, use '.*'.
Error in designfilt (line 224)
[err,requestedResponse,parseParams,h] =
parseAndDesignFilter(inputParamValueNames, varargin{:});
The code (inserted above) is literally copy-pasted from the script, so I cannot figure out what the difference is. I've tried making sure that the "myfilt" variable is cleared each time the function is called just in case there was some problem there. It has no effect. I don't even know what to try next. Any suggestions?

 Accepted Answer

Your code runs for me without error, both in a script and from inside a function the script calls. There must be something in your script file that’s interfering with it.
As a workaround, if you have R2018a or later, consider using the lowpass (link) function.

4 Comments

Thanks for the sanity check!
What kind of thing could be interfering with designfilt though? It's not being passed any variables that could change (as far as I can tell), since all of the parameters are defined right there in the function-call. There's nothing to interact with, as far as I can tell.
My pleasure!
I have absolutely no idea, unfortunately. Since designfilt is a function, and since functions have their own workspaces (that they do not share with the outside world in well-designed code that do not use global variables), the only thing I can suggest is that you have a gremlin in your ‘function embedded in a larger script’. I realise that’s not very helpful, however I have no other explanation. I must leave it to you to find the gremlin.
By the sound of things, there must be a wayward global variable in one of the [non-Mathworks] toolboxes I'm using, which is colliding with designfilt's workspace. I hadn't even considered the possibility that somebody would do that, but at least now I know what to search for! Thanks for your insights.

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!