|
From: Elliot J. B. <ell...@fd...> - 2009-11-12 16:06:45
|
I'm having trouble running a block of code that makes calls to a function
that saves data to and then loads it from an external file. For example, I
have written the function 'my_func':
function R = my_func(n)
[r,v]=system('echo -n $PPID');
idx = regexp(v, '\^\[$');
if ~isempty(idx)
v = v(1:idx-1);
end
filename = ['/tmp/my_func_file_' v '.mat'];
save(filename, 'n');
n = load(filename);
system(sprintf('rm %s', filename));
R = n;
I then call my_func multiple times from test.m:
my_func(3)
my_func(4)
my_func(5)
If I run test.m using 'Save and Go', it works fine. But if I highlight the
three calls to my_func and run them using 'Run Region' I get the following:
>> my_func(3)
/bin/bash: -c: line 0: syntax error near unexpected token `('
my_func(4)
my_func(5)
/bin/bash: -c: line 0: `rm /tmp/my_func_file_11093my_func(4)'
ans =
n: 3
>> my_func(4)
/bin/bash: -c: line 0: syntax error near unexpected token `('
my_func(5)
/bin/bash: -c: line 0: `rm /tmp/my_func_file_11093my_func(5)'
ans =
n: 4
>> my_func(5)
ans =
n: 5
Any suggestions how to solve this?
Thanks.
- Elliot
|