MATLAB/Octave

From Wikiversity
Jump to navigation Jump to search

Installing GNU Octave 3.8 (GUI version)[edit]

As of 9/1/2014 we were unable install the latest version of Octave, which is a 3.8 version with a Matlab-like GUI.

Installing GNU Octave 3.6.4[edit]

This runs in batch mode, which will at first seem alien to those accustomed to the menu of a GUI. But after a while, typing in the command mode will seem easier. The only drawback is that you need to be confident of your MATLAB coding skills because you won't want to run the code every time you write a new line.

Command window[edit]

  • It is important to learn these commands

(For more information see https://www.gnu.org/software/octave/doc/interpreter/System-Utilities.html)

  1. help *command* gives help for a command.
  2. cd *directory* moves into the named directory
  3. dir shows the contents of the current directory
  4. cd .. moves up to the parent directory
  5. mkdir *directory* creates the named directory in the current directory
  6. rmdir *diretory* removes the named directory
  7. rename *oldfile* *newfile* renames a file
  8. copyfile *oldfile* *newfile* changes from the old filename to the new.
  9. pwd shows the path to the current working directory (useful for knowing how to find the folder using Windows)
  10. q stops the output (but does not display if one attempts to learn about it using help q)
  11. path prints out a lot of something and is why you need to learn the q command.
  12. diary *filename* creates a file with a record of command window statements
  13. quit quits the program (if you close without using it you get an error message)

Organizing files[edit]

Here is one procedure for organizing your files

  1. Make a folder in a convenient place. It can either be your desktop, or if you are using campus computers, a flash drive or the "campus cloud". For our purposes this folder will be called OctaveConvenient. You will install shortcuts to Octave and Notepad++ into OctaveConvenient. You might want to store internet to some of the links already mentioned.

Installing[edit]

  1. Install Octave 3.6.4 from http://www.gnu.org/software/octave/ Verify that it works by opening it and typing 2+3 (enter). You should get 5. Then type quit
  2. Install Notepad++ from http://notepad-plus-plus.org/.
  3. Make a bookmark to our "textbook" at https://www.gnu.org/software/octave/doc/interpreter/
    1. Another resource ishttp://en.flossmanuals.net/command-line/gnu-octave/
  4. If you are using Windows, make a file that we shall call Octave_convenient that will contain
    1. shortcuts to these programs
    2. a journal written in either Notepad++ or your favorite word processor
    3. shortcuts to the files that Octave uses to store files and programs (you will create these later)
  5. From Octave, use pwd to deduce where Octave resides and put a shortcut to that place in your folder. Use dir to see what folders you have and cd newname where newname is a folder that you will use to store your programs. Write the as newprogram.m files but call them from Octave by typing newname without the .m extension.

First batch program[edit]

Open Octave and type dir to verify that no folder called myfiles exists. Then type

mkdir myfiles

Verify that you have created myfiles by typing dir. Then type

pwd

to find the location myfiles on your computer. Use that information to create a shortcut to myfiles in Octave_convenient.

Open Notepad++ and write the following:

close all; clear all;clc;
s='hello world'

Do NOT put a semicolon ; after the last line. Save the code as a hello.m (MATrix Laboratory) file, and save it in your myfiles directory that you see when you type dir from the command window in Octave. Use cd myfiles to go into that folder and verify that hello.m is in your active directory. Now type into your command window:

hello

You should see "hello world". Now you can type

quit

Congratulations, you have just run your first batch program!


Footnotes[edit]


See also[edit]

  • datamash command-line program which performs basic numeric and statistical operations