MATLAB coder - can't get the 'coderand' .exe to work correctly

Hi. I'm running MATLAB C-coder for the first time, running through the 'coderand' example.
https://uk.mathworks.com/help/releases/R2015b/coder/ug/ standalone-c-c-executables-from-matlab-code.html
It works to produce C source code, (which is not overly clear) a MEX file and an executable. The MEX file works fine
Trial>> coderand_mex
ans =0.2785
Trial>> coderand_mex
ans =0.5469
Trial>> coderand_mex
ans =0.9575
but the .exe file doesn't seem to work, running inside MATLAB or a DOS cmd window. It produces the same number each time its ran
C:\ALL\SOAR\MATLAB_DEV\coder_play>coderand.exe
coderand=0.814724
C:\ALL\SOAR\MATLAB_DEV\coder_play>coderand.exe
coderand=0.814724
C:\ALL\SOAR\MATLAB_DEV\coder_play>coderand.exe
coderand=0.814724
I set the tool t build for MATLAB Windows Host and the Compiler to MinGW64 (I know this can cross compile too), but say it was creating a Linux binary, I would expect a .bin file output and I would not expect it to run.
(i) Can somebody explain what settings I have missed or wrong. (ii) Can somebody explain the some basis to the source code generation, I know that generating 'true' random numbers is something of a science topic The .exe produced is 61K, I would expect something a lot less.
(iii) It would be re-assuring if this example included some output too. I have covered many aspects of MATLAB & its toolboxes and add-ons in recent weeks and this is the first time that I've fully stumbled
Thanks, Mike B

댓글 수: 4

"(i) Can somebody explain what settings I have missed or wrong." I do not see an evidence that anything went wrong or is missing. Why to you expect a ".bin" file and which operation should create such a file?
You expect the executable to be smaller than 61kB, but how can we help then? I think you have to adjust your expectations to the real file size, not the other way around.
"explain the some basis to the source code generation" what exactly do you want to know? It is not useful to explain all we know in every detail.
You will get the same pseudo-random numbers, if the random number generator is initialized with the same values. I'm not sure, which code you are running actually. Does it contain any dynamic initialization to set the seed of the RNG? Perhaps considering the current time, name of the machine, process ID, IP, MAC-address or anything other unique and random like a GUID? IF not, it is expected that the RNG produces the same values.
Conclusion: I do not understand, what you question is. Please elaborate this a little bit.
Jan
Jan 2018년 5월 15일
편집: Jan 2018년 5월 15일
[MOVED from flag] michael brewin wrote:
Nobody has answered this question in several days - how can I get a MATLAB support Engineer to repsond
@michael: You can contact the technical support by using the "Contact Us" link on top of this page, or https://www.mathworks.com/company/aboutus/contact_us.html
michael brewin
michael brewin 2018년 5월 15일
편집: michael brewin 2018년 5월 15일
I hoped that the question was really simple. The coderand example is the most simple MATLAB example that I have seen. So it is only 2 lines.
function r = coderand() %#codegen r = rand();
I expected that this would get transformed into an quivalent 'C' rand function and produce different values each time, as the MEX file does.
There is no documentation that I can find as to how the rand function operates, what it uses as its seed etc. I didn't expect a 61K .exe file from it, but that point is secondary. The fact is that the example doesn't work on my ordinary machine and there is nothing I can think of that I can have set wrong. Please can you just run this line through the C coder and tell me if it works.
Thankyou for the URL for support, I have bookmarked it.
Mike.
You do not have to bookmark the "Contact Us" link, because you find it on all pages of the MathWorks sites.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2018년 5월 16일
To get a documentation about rand, see doc rand. At the bottom there is the link: Why Do Random Numbers Repeat After Startup?. There you find the example:
If you want to avoid repeating the same random number arrays when
MATLAB restarts, then execute the command,
rng('shuffle');
Insert this before r = rand().

댓글 수: 4

Hello Jan, thanks for your help. So the problem was once the C-coder had been used it generated the same number. So, I added your line in and we're still good in MATLAB.
function r = coderand(rngtype1, rngtype2) %#codegen
rng(rngtype1,rngtype2);
r = rand();
end
I can run this with
coderand('shuffule,'twister')
but I now I can't get the C-coder to build code. It fails at generation saying I must provide the input argument as 'shuffle' - which I do !
As far as I can see I give it exactly correct inoput arguments. It asks for 'shuffle' as an option and that's what I'm entering. Please see attachments. Thanks, Mike
Did you ever get this working? I'm trying to write a program that accepts command line inputs and have been very unsuccessful. You can see my woes here. Any help would be appreciated.
'shuffule' is not the same as 'shuffle'
Hi. yes, you're right, but If you see the .png file, the command syntax was correct, 'shuffle' ...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

질문:

2018년 5월 4일

댓글:

2019년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by