Octave Issues

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

User avatar
Meteorswarm
Posts: 979
Joined: Sun Dec 27, 2009 12:28 am UTC
Location: Ithaca, NY

Octave Issues

Postby Meteorswarm » Tue Feb 02, 2010 1:46 am UTC

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.
The same as the old Meteorswarm, now with fewer posts!

Kaldra
Posts: 32
Joined: Mon Apr 20, 2009 3:28 am UTC

Re: Octave Issues

Postby Kaldra » Tue Feb 02, 2010 4:52 am UTC

The best I've found is control + C and right click->paste.

But then again, I haven't done much in octave. But it's been coming up more and more in various classes, so I'm interested in this as well.

User avatar
Meteorswarm
Posts: 979
Joined: Sun Dec 27, 2009 12:28 am UTC
Location: Ithaca, NY

Re: Octave Issues

Postby Meteorswarm » Tue Feb 02, 2010 2:05 pm UTC

Kaldra wrote:The best I've found is control + C and right click->paste.

But then again, I haven't done much in octave. But it's been coming up more and more in various classes, so I'm interested in this as well.


I mean, I can put it in a file, but I can't figure out how to run the file. Octave [filename] will test if it compiles, but nothing else.
The same as the old Meteorswarm, now with fewer posts!

User avatar
SWGlassPit
Posts: 312
Joined: Mon Feb 18, 2008 9:34 pm UTC
Location: Houston, TX
Contact:

Re: Octave Issues

Postby SWGlassPit » Fri Feb 05, 2010 3:39 pm UTC

In octave:
octave:1> run 'filename'

Alternatively, you can put the following line at the beginning of your script:
#!/usr/bin/octave
and chmod 755 the script, whereupon you may simply run the script from the command line.
Up in space is a laboratory the size of a football field zipping along at 7 km/s. It's my job to keep it safe.
Image
Erdös number: 5

rabuf
Posts: 15
Joined: Thu Mar 20, 2008 2:30 pm UTC

Re: Octave Issues

Postby rabuf » Fri Feb 05, 2010 11:51 pm UTC

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

User avatar
Meteorswarm
Posts: 979
Joined: Sun Dec 27, 2009 12:28 am UTC
Location: Ithaca, NY

Re: Octave Issues

Postby Meteorswarm » Sat Feb 06, 2010 5:16 am UTC

Yeah, I somehow managed to screw something up before, but I have it working now. Now I just need to make multi-function files for the assignment, but at worst I can use a lab computer with matlab after doing all the development in octave, and then just put the stuff together and verify that it works.
The same as the old Meteorswarm, now with fewer posts!


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 5 guests