Meteorswarm wrote:I'm taking a numerical analysis class that is Matlab dependent, but I'm cheap and an oss fanatic, so I'm trying to use octave. This isn't really an issue, but I can't figure out how to get scripts to work. For my first assignment I have a function I'd like to test (and use), but none of the instructions I've been able to find work to load it into the interpreter.

Code: Select all

`function C = MatSquare(H)`

%do some stuff I'm not going to put in here

C = H*H %well, this is the ultimate effect, at least

end

I want to put this function in a file and then run it on data in the interpreter. I should note that I'm doing my developing in vim and a bare terminal, not in an IDE with compiling support.

Save it into a file called MatSquare.m in some directory, say '~/numanal'. Then do:

Code: Select all

`$ cd ~/numanal`

$ octave

octave> MatSquare(AMatrix)

Within octave (and matlab) you can use cd to move around the directory structure so if you started off in ~/ you could do:

Code: Select all

`octave> MatSquare(AMatrix)`

SOME ERROR MESSAGE ABOUT NOT KNOWING THAT FUNCTION (sorry octave isn't on this machine)

octave> cd numanal

octave> MatSquare(AMatrix)

And finally, like in *nix systems matlab and octave (should, haven't actually done this one) have a PATH variable, if you add ~/numanal to the PATH variable then the file will be accessible from any directory.

Some things to keep in mind if most of your development is in octave but must be able to run in matlab (similarly if the prof or text provides source files that won't run in octave):

http://www.gnu.org/software/octave/FAQ.html#MATLAB-compatibility