C library for mvnrnd and randn

4 vues (au cours des 30 derniers jours)
Jane Jean
Jane Jean le 3 Avr 2012
Hello,
does anybody know a library which provides more or less the same functions as mvnrnd and randn of Matlab? The library must be also usable in within a mexFunction.
Thank you!
  2 commentaires
Titus Edelhofer
Titus Edelhofer le 3 Avr 2012
Hi Jane,
I'm getting curious your mexFunction questions: why do you need all the things MATLAB provides as mex functions? Or are the mex functions needed to compare MATLAB and your hand written C code? If the latter is the case, you might want to take a look at MATLAB Coder (www.mathworks.com/products/matlab-coder) instead of writing everything by hand ...
Titus
Jane Jean
Jane Jean le 3 Avr 2012
Hi, thanks for the reply.
I am porting algorithm written in Matlab into C so that when the program is delivered to the client, the algorithm is kept secret. Therefore all code must be written in C. Furthermore, the client's matlab version might not contain mvnrnd function.
I thought of using Coder but I don't have this tool at my workplace. So I was wondering if it's possible to just use a C library which provides these functions.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 3 Avr 2012
For randn see e.g. Knuth v2, 3rd ed, p122.,
U1 and U2 are uniform on (0,1), then
X = Variance * cos(2*pi*U1) * sqrt(-2*ln(U2)) + Mean;
Or the same for SIN instead of COS.
You will find more resources by asking your favorite internet search engine.
Converting everything into C requires a lot of time for coding and testing. Buying the Coder might be cheaper in total. P-coding is even cheaper and it hides the source code efficiently. On the other hand each call to each toolbox function can be tracked by using the debugger. E.g. this cannot be hidden successfully:
if strcmp(input('Password', 's'), 'Password1')
granted=true;
end
x = rand(3, 4);
y = sin(x);
z = sum(y, 2);
This is just a meaningless example. It will need less than a minute to reveal this code when it is P-coded.
  5 commentaires
Titus Edelhofer
Titus Edelhofer le 3 Avr 2012
One thing to notice about MATLAB Coder: it can also generate a MEX file that runs the generated C code. Doing this is a good way to check if the generated C code and the MATLAB code lead to the same results (up to numerical roundoff, of course).
And a fact that might give some confidence in the quality of the code: although MATLAB Coder came out with R2011a the first time, the technology behind has a longer history as "emlc" being a part of Real-Time Workshop (today Simulink Coder).
Jan
Jan le 3 Avr 2012
@Jane: The tracking of toolbox functions is easy in P-files, but much more complicated in the Coder-created files.

Connectez-vous pour commenter.

Plus de réponses (1)

Titus Edelhofer
Titus Edelhofer le 3 Avr 2012
Hi Jane,
if protecting IP is your concern, you might want to try pcode: it comes with MATLAB and encrypcts the algorithm as well ...
Titus
  1 commentaire
Jane Jean
Jane Jean le 3 Avr 2012
Thanks for the suggestion. I'll talk to my boss about this and see if he still wants to convert everything into C.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by