mex file gives two different results. what is the cause?

조회 수: 2 (최근 30일)
Itzik Ben Shabat
Itzik Ben Shabat 2016년 7월 27일
댓글: Honglei Chen 2016년 7월 28일
Hello, I am running a mex file that i compiled on my pc. I expect that for the same input the result would be the same. however, this is not the case - the first and second runs (for the same input) give completely diferent results. I am lost and dont know even what to look for. does anyone know what could be the cause of this abnormal phenomena?

답변 (2개)

Honglei Chen
Honglei Chen 2016년 7월 27일
maybe you have some random number in functions you use? Could you try to run
rng(0)
before each run of your script and see if it still produces different results?
  댓글 수: 2
Itzik Ben Shabat
Itzik Ben Shabat 2016년 7월 27일
no random numbers. but there is a global variable that seems to have beenthe problem. why is that?
Honglei Chen
Honglei Chen 2016년 7월 28일
I'm wondering if you updated the global variable in your first run but didn't reinitialize it in the second run? Maybe you can try the "clear" command between each run to see if that's the case?

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


Walter Roberson
Walter Roberson 2016년 7월 27일
You are probably either corrupting memory or using uninitialized memory.
  댓글 수: 2
Itzik Ben Shabat
Itzik Ben Shabat 2016년 7월 27일
There is a global variable that seems to have beenthe problem. but not sure how could that be corrupted (and im initializing it, however when i changed the location of initialization it solved it) why is that?
Walter Roberson
Walter Roberson 2016년 7월 27일
Did you declare the variable as global in every routine you use it in? You need to specifically "global" the variable in each function you want to use the value in.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by