normrnd, normpdf, pdf not working for code generation

2 views (last 30 days)
I'm trying to use MATLAB Coder to compile a script with normrnd, normpdf and pdf functions. However, I keep getting errors saying these functions are not supported for code generation, even though according to the online documentation it is supported. Could someone tell me a workaround for this issue?
I want to avoid using coder.extrinsic to ensure the compiled code runs as fast as possible. Could it have something to do with the fact that I am using objects?
Thank you,
Jai

Accepted Answer

Mike Hosea
Mike Hosea on 3 Jul 2014
If you're using 2013a or earlier, they aren't supported. If you're using 2013b or later, they are supported. You'll need the obvious licenses, of course, but it sounds like you have them if you can call those functions from MATLAB and you can compile anything with MATLAB Coder. Could be an installation issue. Do you have a toolbox/stats/eml/ directory?
Also, I'm assuming we're talking about errors when compiling, because if the screener tool has it wrong then the problem would most likely be limited to the screener tool.
  2 Comments
Jai
Jai on 3 Jul 2014
Oh I see, thanks. I do have 2013a, which is probably why I'm getting the error. I do have the stats library so that can't be the problem. DO you know if using coder.extrinsic makes the compiled code a lot slower?
Mike Hosea
Mike Hosea on 3 Jul 2014
Edited: Mike Hosea on 3 Jul 2014
It's probably not going to be much slower in the case of normrnd and normpdf. Some of the distributions you can access through pdf() might be faster when compiled. Of course you can only use extrinsic functions for mex targets. Also, be sure that you pre-define the output type. For example,
coder.extrinsic('normrnd');
y = zeros(m,n);
y = normrnd(mu,sigma,m,n);
Looks like a redundant definition of y, but in fact it tells the compiler what the size and class of the output of normrnd is going to be.
Another approach is to write your own normrnd and normpdf. The former is built on randn (which does the heavy lifting--just need to transform the output to have the mean and standard deviation you want), and the latter is a textbook sort of thing. Other distributions accessible through pdf() can, I admit, be much more involved.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!