I am currently working on shell script in GRASS GIS and Ubuntu. At some point, I must run a calculation (based on an ascii grid) that I have available as Matlab script and .exe (created from Matlab I believe). For that I must exit GRASS (and boot into Windows), but it would be neat if I could somehow run this from inside GRASS GIS (or at least stay inside Ubuntu). For the non-Matlab and Python-expert...what would be a sensible approach? From what I have understood, converting to Python might be the only real option.

  • Please edit the thread title. It should be a question which indicates what the thread is about. – underdark May 8 '14 at 16:41

1) If you want to run the script from inside GRASS GIS, it is relatively easy to transform the original Matlab script (.m) in a Python script if it do not uses specific toolboxes (with numpy and the others scientific Python modules)

2) if you want to run the .m script outside GRASS GIS, you can use Octave, open source alternative to run m-code (MATLAB Programming/Differences between Octave and MATLAB) or FreeMat or SciLab (other alternatives)

3) but you can also look if GRASS GIS cannot do directly your processing.

| improve this answer | |

I found two solutions, which seem to work:

1) copy the Octave script/function you want to run into the folder accessed by GRASS GIS. Call it with octave --silent --eval [...] as you would in shell. A simple example: my function is "add.m", and looks like:

function c = add (a,b) 
c = a+b;`

In the command console in GRASS I run octave --silent --eval add(a=5,b=6). The output is ans=11.

2) write an executable. it must have a header in the form "#! /usr/bin/octave -qf"

For example: I create a text file with the name add and the text:

#! /usr/bin/octave -qf
c=add (a,b)

In the terminal (converts it into an executable): $ chmod 755 add In the GRASS console run: ./add Output: c=11.

I have not yet done this with more complex scripts and import/export into/from GRASS GIS and Octave (e.g. ascii files), but it should work with this approach.

(Python is probably a more powerful way, but I am accustomed to shell)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.