By default, Octave will look for your codes in the folder C:\Program Files\Octave. You can check this using the present working directory ’pwd’ command as follows:
octave-3.0.3.exe:1>pwd
ans=C:\Program Files\Octave
It’s a good idea to create a new folder in which you can save all your code files. For example, create the folder “M Octave Codes” in “My Documents” and make this new folder the current working directory by using the change directory command ’cd’ as follows:
octave-3.0.3.exe:2>cd “C:/Documents and Settings/My Documents/My Octave Codes”
octave-3.0.3.exe:3>pwd
ans=C:\Documents and Settings\My Documents\My Octave Codes
An alternative way to change the working directory is by editing the properties of the Octave Desktop Icon. Right click the Octave Desktop Icon, select “Properties” and then edit the “Start In:” folder to be your code folder. When you start Octave, the working directory will automatically be the folder you specified in the “Start In:” field.
2. Using the Editor to create Script Files
To open the editor, just type the command ’edit’ at the prompt.
octave-3.0.3.exe:1>edit
The editor opens in a new window. You might have to install a suitable editor (see installation instructions) for this to work.
You can type up commands you want Octave to run in the Editor and save them in an M-file so that you do not have to type them again if you need to rerun the commands. For example, let’s create the following simple script file to plot a sine wave. Type the following commands in the editor:
%Script file to plot a sine wave
x=0:0.01:2*pi;
plot(x, sin(x));
xlabel(’x’);
ylabel(’y=sin x’);
Then select File>Save As and save the file as script1.m in your code folder.
To run the file, go to the Octave prompt and type
octave-3.0.3.exe:2>script1
You should see a figure window with the sine plot.
3. Printing a Figure in Octave
To print the plotted figure in encapsulated postscript format, use the following command
octave-3.0.3.exe:3>print graph1.pdf
This will save the plot as graph1.pdf in your code folder.
Otherwise, if you would like to copy the figure to a word processor and then print it, go to the figure window and select the icon corresponding to the “Copy the plot to the clipboard” command, as shown in the image below. You can then paste the plot to your favourite word processor.
General
MATLAB Resources
Octave Resources
Octave Tips
More tips are available on the FAQ page.
1. Changing Directory in Octave
By default, Octave will look for your codes in the folder C:\Program Files\Octave. You can check this using the present working directory ’pwd’ command as follows:
octave-3.0.3.exe:1>pwd
ans=C:\Program Files\Octave
It’s a good idea to create a new folder in which you can save all your code files. For example, create the folder “M Octave Codes” in “My Documents” and make this new folder the current working directory by using the change directory command ’cd’ as follows:
octave-3.0.3.exe:2>cd “C:/Documents and Settings/My Documents/My Octave Codes”
octave-3.0.3.exe:3>pwd
ans=C:\Documents and Settings\My Documents\My Octave Codes
An alternative way to change the working directory is by editing the properties of the Octave Desktop Icon. Right click the Octave Desktop Icon, select “Properties” and then edit the “Start In:” folder to be your code folder. When you start Octave, the working directory will automatically be the folder you specified in the “Start In:” field.
2. Using the Editor to create Script Files
To open the editor, just type the command ’edit’ at the prompt.
octave-3.0.3.exe:1>edit
The editor opens in a new window. You might have to install a suitable editor (see installation instructions) for this to work.
You can type up commands you want Octave to run in the Editor and save them in an M-file so that you do not have to type them again if you need to rerun the commands. For example, let’s create the following simple script file to plot a sine wave. Type the following commands in the editor:
%Script file to plot a sine wave
x=0:0.01:2*pi;
plot(x, sin(x));
xlabel(’x’);
ylabel(’y=sin x’);
Then select File>Save As and save the file as script1.m in your code folder.
To run the file, go to the Octave prompt and type
octave-3.0.3.exe:2>script1
You should see a figure window with the sine plot.
3. Printing a Figure in Octave
To print the plotted figure in encapsulated postscript format, use the following command
octave-3.0.3.exe:3>print graph1.pdf
This will save the plot as graph1.pdf in your code folder.
Otherwise, if you would like to copy the figure to a word processor and then print it, go to the figure window and select the icon corresponding to the “Copy the plot to the clipboard” command, as shown in the image below. You can then paste the plot to your favourite word processor.