0

I have a file named myfunction.m, the content is:

function []=myfunction()
Z = normrnd(0,1)

Each time I issue the comman myfunction in matlab, I get a random result.

Then, I compile myfunction.m using this command:

mcc -m myfunction.m

and I obtain an excutable named myfunction.

And I try to excute it in matlab using this command:

!myfunction

However the results I get are no longer random...instead it is a fixed number, which is 0.5377..

This is so wired. Why? My OS is linux.

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
  • Are you [randomly seeding](http://www.mathworks.es/es/help/matlab/ref/rng.html) the random number generator (using current time for example)? Try adding `rng('shuffle')` at the start of your code (for recent versions of Matlab) – Luis Mendo Jun 26 '14 at 18:38
  • Tanks very much Luis. That works! – happycharleswang Jun 27 '14 at 12:28

0 Answers0