Use Matlab with Xgrid

Nov 26, '04 09:16:00AM

Contributed by: Anonymous

It is possible to use MATLAB with Xgrid. Until recently, every time I tried this, MATLAB either failed to start or would immediately die with a "bus error" after starting. However, I discovered through trial and error that Matlab simply requires that the HOME environment variable exists.

So the way to use MATLAB is to use a shell script that will set the environment variable correctly, then invoke MATLAB with a numerical argument. Read the rest of the hint for an example...

  1. Create a shell script called matlabfoo.sh:
    #!/bin/sh
    
    # For some reason, MATLAB dies if you don't have
    # HOME set in environment
    export HOME=/home/username
    
    X="foo(${1})"
    
    /Applications/MATLAB7/bin/matlab -nojvm -nodisplay -r $X ;
    
    As you see, you have to make sure you call MATLAB with the nojvm argument, or else it will complain about not being the console user. The -r argument lets you specify a function to run. In this example, the shell variable X is used to pass a different input argument, based on what Xfeed supplies from the range agument.

  2. Create a MATLAB function called foo (foo.m):
    function foo(in)
      try
        disp(['in was: ',num2str(in)])  
        % Now do something
        A = [(in-1)*10+1:(in*10)];
        disp(A)
      catch
        disp('Something went wrong')
        disp(lasterr)
      end
    
      % It is critical that your task ends with "exit"
      exit
    
  3. Put these in a directory called matlab_test

  4. Create a directory to store results called matlab_out

  5. Launch Xgrid, then choose the Xfeed plugin. Give it the following arguments (final settings screenshot):
When you hit "Submit Job," you should get the results in your matlab_out directory. For example, sh_matlabfoo.sh_5.txt:
                              < M A T L A B >
                  Copyright 1984-2004 The MathWorks, Inc.
                         Version 7.0.0.19901 (R14)
                                May 06, 2004

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
in was: 5
    41    42    43    44    45    46    47    48    49    50
[robg adds: I haven't tested this one.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041125065000639