How to unfix the seed with Matlab engine?

3 Ansichten (letzte 30 Tage)
cmar
cmar am 19 Sep. 2019
Beantwortet: Steven Lord am 19 Sep. 2019
I'm try to use random function in a Matlab function which is called by a python program. Unfortunately, the seed seems to be fixed by the matlab engine because the function called in Matlab works, but when it is called through Python it always returns the same values.
I isolated the problem by calling several times this python program :
import matlab.engine
import random
if __name__ == "__main__":
# Start matlab
eng = matlab.engine.start_matlab()
print(random.random())
print(eng.rand(1, 1, nargout=1))
# Close Matlab
eng.quit()
I obtained different values for the python random function, but the value for the Matlab function is always the same. I use Matlab 2015a and python 2.7.

Akzeptierte Antwort

Steven Lord
Steven Lord am 19 Sep. 2019
Every time you call matlab.engine.start_matlab you're starting a new MATLAB process. See this documentation page for how to "Generate Random Numbers That Are Different".

Weitere Antworten (0)

Kategorien

Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange

Produkte


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by