If I run the same script simulatneously on deifferent windows, can I get false results?
1 view (last 30 days)
Show older comments
If I run the same script simulatneously on deifferent windows, but with different parameter which I put in by hand, can I get false results because matlab might confuse betweeb the different runs? I should stress that I change the parameter by changing several values of variables withing the code itself, then save the fuile and run again. I'm not reading any data manually while script is running. THX!
1 Comment
Geoff Hayes
on 13 Mar 2016
Erez - by different windows do you mean different instances of MATLAB? Are both instances using the same function (m file)?
Accepted Answer
Walter Roberson
on 13 Mar 2016
If you have different MATLAB instances, then they can get confused if:
- your program modifies source code while they are running
- you write or save to the same file without taking steps to synchronize the access
- you use the same memory-mapped file with memmapfile
- you somehow share an object with state such as saving an open videoreader and restoring it in multiple places
- you use shared memory segments with the same key (a pretty advanced use that requires some C/C++ code to set up the shared memory)
However, if you are just executing the same .m code and writing to different files, then the sessions will not get confused.
2 Comments
Walter Roberson
on 13 Mar 2016
Source code is .m files. For example if you have
function generate_lucky(M)
fid = fopen('lucky.m', 'wt');
fprintf(fid, 'function r = lucky()\n');
fprintf(fid, 'r = randi([1 %d])\n', M);
fclose(fid);
clear lucky
Then each time generate_lucky was run, it would write a new lucky.m . If you had multiple sessions calling lucky, then the changes made to the .m code in one could confuse the running of the other session.
(Source code can also be .mex* files or any other programming language, if you are calling the code from inside MATLAB. For example if you rewrote a Java .jar from inside one session and were calling it from your code, the other session might get confused.)
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!