Showing posts with label MatLab. Show all posts
Showing posts with label MatLab. Show all posts

Jan 15, 2013

Generate random number in old version Matlab


If you want to have different a sequence of random numbers when the program is run for multiple times, a seed has to be set. The function "rand('state', int)" can not do it.

The old version Matlab which is lower than v7.7 has no some common random number generators. You can not use RandStream or rng() to set the random seeds. So I use an extended random number generator which can be downloaded from http://people.sc.fsu.edu/~jburkardt/m_src/asa183/asa183.html (r8_random.m).

s1 = mod ( 171 * s1, 30269 );

s2 = mod ( 172 * s2, 30307 );

s3 = mod ( 170 * s3, 30323 );

r = mod ( s1 / 30269.0 ...

+ s2 / 30307.0 ...

+ s3 / 30323.0, 1.0 );

return



We just need to set different seed s1,s2,s3 at the beginning of your program each time when you run it and it will generate different random sequences.

Mar 9, 2011

MATLAB will crash when using FIGURE or PLOT function. Solution to version R2008b on Mac OS


I use MatLab R2008b all the time. But after I upgrade my Mac OS, it always crashes when the PLOT or FIGURE function is called.

Now MathWorks post the solution as the following,

The crash is possibly related to upgrading the Mac OS to version 10.5.8 or 10.6.8. This issue has been seen in MATLAB R2007a, R2007b, and R2008a, including both Professional and Student versions. Please note that OS 10.6 is not officially suported for MATLAB R2007a, R2007b, and R2008a.

Configurations reported with this crash:

================================

Mac OS 10.6.8 with Java 1.6.0_26

Mac OS 10.5.8 with Java 1.5.0_30

================================

If MatLab upgrading is not an option, as a workaround, replace a statement in the matlabrc.sh file as follows:

< Step 1 >: Close MATLAB, if there is any session open.

< Step 2 >: Locate the file, 'matlabrc.sh' as follows, In Terminal or xterm , type:

open -a TextEdit /Applications/MATLAB_R2008a/bin/.matlab7rc.sh

< Step 3 >: Open the matlabrc.sh file in the editor to replace a line as follows,

Navigate to Line 407,

if [ "$DYLD_LIBRARY_PATH" != "" ]; then

DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH

else

DYLD_LIBRARY_PATH=

fi


Change the line "DYLD_LIBRARY_PATH=" to "DYLD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Libraries"

< Step 5 >:
Save the changes by pressing "Command" + "s" keys.

< Step 6 >:
Restart MATLAB.

Reference: http://www.mathworks.com.au/support/solutions/en/data/1-F37IJB/index.html