Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GNU Octave Beginner's Guide

You're reading from   GNU Octave Beginner's Guide Become a proficient Octave user by learning this high-level scientific numerical tool from the ground up

Arrow left icon
Product type Paperback
Published in Jun 2011
Publisher Packt
ISBN-13 9781849513326
Length 280 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jesper Schmidt Hansen Jesper Schmidt Hansen
Author Profile Icon Jesper Schmidt Hansen
Jesper Schmidt Hansen
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

GNU Octave
Credits
About the Author
About the Reviewers
1. www.PacktPub.com
2. Preface
1. Introducing GNU Octave FREE CHAPTER 2. Interacting with Octave: Variables and Operators 3. Working with Octave: Functions and Plotting 4. Rationalizing: Octave Scripts 5. Extensions: Write Your Own Octave Functions 6. Making Your Own Package: A Poisson Equation Solver 7. More Examples: Data Analysis 8. Need for Speed: Optimization and Dynamically Linked Functions Pop quiz - Answers

Time for action - editing the .octaverc file


  1. 1. Start Octave if you have not already done so, and open the default editor:

    octave:1> edit
    
    
  2. 2. Copy the following lines into the file and save the file as .octaverc under the Octave home directory if you use Windows, or under the user home directory if you use GNU/Linux. (Without the line numbers, of course.) Alternatively, just use your favorite editor to create the file.

    PS1 (">> ");
    edit mode "async"
    
  3. Exit the editor and restart Octave. Did the appearance of the Octave prompt change? It should look like this

    >>
    

    Note

    Instead of restarting Octave every time you make changes to your setup files, you can type, for example, octave:1> source(".octaverc"). This will read the commands in the .octaverc file.

What just happened?

PS1(">> ") sets the primary prompt string in Octave to the string given. You can set it to anything you may like. To extend the preceding example given previously, PS1("\\#>> ") will keep the command counter before the>> string. You can test which prompt string is your favorite directly from the command prompt, that is, without editing .octaverc. Try, for example, to use \\d and Hello give a command, \\u. In this book, we will stick with the default prompt string, which is \\s:\\#>.

The command edit mode "async" will ensure that when the edit command is given, you can use the Octave prompt without having to close the editor first. This is not default in GNU/Linux.

Finally, note that under Windows, the behavior will be global because we instructed Octave to look for this particular .octaverc file every time Octave is started. Under GNU/Linux, the .octaverc is saved in the user's home directory and will therefore only affect that particular user.

More on .octaverc

The default editor can be set in .octaverc. This can be done by adding the following line into your .octaverc file

edit editor name of the editor

where name of the editor is the editor. You may prefer a notepad if you use Windows, or gedit in GNU/Linux. Again, before adding this change to your .octaverc file, you should test whether it works directly from the Octave prompt.

Later in the book, we will write script and function files. Octave will have to be instructed where to look for these files in order to read them. Octave uses a path hierarchy when searching for files, and it is important to learn how to instruct Octave to look for the files in certain directories. I recommend that you create a new directory in your home directory (Octave home directory in Windows) named octave. You can then place your Octave files in this directory and let the interpreter search for them here.

Let us first create the directory. It is easiest simply to enter Octave and type the following:

octave1:> cd ~/
octave2:> mkdir octave

It should be clear what these commands do. Now type this:

octave3:> edit .octaverc

Add the following line into the .octaverc file:

addpath("~/octave");

Save the file, exit the editor, and restart Octave, or use source(".octaverc"). At the Octave prompt, type the following:

octave1:> path

You should now see that the path ~/octave/ is added to the search path. Under Windows, this path will be added for all users. The path list can be long, so you may need to scroll down (using the arrow key) to see the whole list. When you reach the end of the list, you can hit the Q key to return to Octave's command prompt.

You have been reading a chapter from
GNU Octave Beginner's Guide
Published in: Jun 2011
Publisher: Packt
ISBN-13: 9781849513326
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime