## Introduction

MATLAB is an incredibly powerful tool for engineers, not just for number crunching solutions to specific problems, but as an *aid to creativity*. MATLAB power users sometimes talk about it feeling almost like an extension of their brain. Even for a dyed in the wool C programmer like me, it’s really useful to sketch out algorithms in MATLAB before implementing them in C. MATLAB’s notation for manipulating arrays is wonderfully concise and the ability to visualise data sets at the drop of a hat using its graphing tools really helps the creative process.

The main problem with MATLAB is that its a proprietary platform and even the student version comes with a hefty price tag. This is where Octave comes in – it’s basically an open source implementation of the MATLAB language. There are other free alternatives, like Scilab and FreeMat, but Octave seems to be the one that’s most consistent with MATLAB. Provided that you steer clear of non-compatible toolboxes, your Octave M-files should run fine in MATLAB.

## Installing Octave on Windows

Unfortunately, it’s not immediately obvious how to install Octave on Windows. Visitors to the Octave home page need to do a bit of detective work to find their way to the correct binary executable installer for Windows. Personally, I think it would be really great if the correct download link was given pride of place on the Octave home page. I can’t help wondering whether 9 out of every 10 people who go looking for Octave end up abandoning the idea because they’re not quite sure which version to try.

Fortunately, once you know what to do, installing Octave on Windows is fast and straightforward and *really is* worth the effort. I don’t have MATLAB installed on my laptop at all anymore – I just use Octave.

The exact file to download is “Octave 3.6.4 for Windows Microsoft Visual Studio” which is one of the versions provided on Octave Forge. Here’s the link:

- octave-3.6.4-vs2010-setup.exe (68.2 MB)

Run the installer and accept the default installation location (C:\software\Octave-3.6.4\) and other default options, as shown in the following sequence of screen shots:

Now just wait while the installation takes place…

## Fix for Windows 8

If you’re running Windows 8, you’ll probably run into the same problem I did when I first ran Octave – the command prompt was missing from the command window, as shown below:

If so, you just need to do one small fix on the newly installed Octave to get things working. As a workaround for a gnulib Windows 8 compatibility bug, you need to add some command line switches to the octave.exe desktop shortcut: Right click the Octave desktop shortcut and click on “Properties”. Add the text `"-i --line-editing"` to the end of the Target field. Assuming you installed Octave in the default location (“C:\Software\Octave-3.6.4\”), the complete Target line will be as follows:

C:\Software\Octave-3.6.4\bin\octave-3.6.4.exe -i --line-editing

Here’s how it looked on my laptop:

## Using Octave

Now just click OK and you’re ready to start using Octave. Double click on the desktop shortcut to start it up. Here’s how it looks when I open it on my laptop.

As you can see, it *looks* very different from MATLAB. However, we can type the same commands in Octave that we would use in MATLAB. In the following example, I’ll create an array of time values, use it to generate a sinusoidal function, and then plot the sinusoid in a figure window.

Just like in MATLAB, a sequence of commands can be stored in an M-file. However, you’ll need to use an external text editor. The one I strongly recommend is Notepad++ which is free to download from http://notepad-plus-plus.org/. Notepad++ is an incredibly useful text editor which can be used for all kinds of programming tasks (editing M-files is just one thing it’s good at).

Here’s an example of writing an M-file in Notepad++:

Once I saved my M-file, I ran it in the Octave command window as shown below:

## Useful Octave commands

In the final screen shot above, you can see some useful commands for moving between different folders.

- The
**pwd**command displays the “present working directory” – i.e. the full path of the folder you’re currently in. If you’re trying to run an M-file,**pwd**should display the name of the folder that contains your M-file. - The
**cd**command is used to “change directory” – i.e. move to a different folder inside the one you’re in. - The command
**“cd ..”**leaves the current folder and returns you to the one that contains it. - The
**clc**command clears the command window.

Hi Ted

I am currently working with Octave. But I could not plot anything. The window just stays there once I plot something. Do you have any idea why this happen?

Kaijie

Hi Kaijie,

When you say “the window just stays there”, which window do you mean? Are you referring to the command window? Can you still type in commands or has Octave frozen completely?

Also, if you say what operating system and version of Octave you’re using, that would be useful.

Ted

You need to set graphics_toolkit to gnuplot. Type graphics_toolkit in Octave and if it shows FLTK, then you can change it to gnuplot by typing :-

graphics_toolkit(“gnuplot”);

That should work. But you need to change toolkit in this manner every time you load octave in terminal.

In order to make the changes in the graphics backend permanent you can write the command: graphics_toolkit(“gnuplot”); Inside the file “octaverc”, wich is normally located at Octave\Octave-X.0.0\share\octave\X.0.0\m\startup. Or you can run a simple search inside the folder you chose to install Octave.

source: https://wiki.archlinux.org/index.php/Octave#Plotting

Thanks Felipe – useful tip!

Ted

tried to install on windows 8.1 and faced the problem you describe

tried to fix it the way you show but it’s telling me that the name i chose for the target is not valid and to chek the path and the name

could you help me?

Hi Achilleas,

All I can think of is that maybe you have an error in the path to the Octave exe file. My target line is:

…but your target line may need be different if you installed Octave in a different location, or if you installed a different version number (rather than version 3.6.4). Could something like that be the explanation?

Ted

C: \ Software \ Octave-3.6.4 \ bin \ οκτάβα-3.6.4.exe -i –line-editing

May be you are trying to put “-i –line-editing” along with the path name.

Use this:

“C:\Program Files (x86)\Mi app\Octave-3.6.1\bin\octave-3.6.1.exe” -i –line-editing

After saving my Notepad++ with the same algoritm than yours, i call it on Octave window as you do but an error appears “vc100libtiff-3.dll is missing”

Hi Joand,

Sorry I haven’t come across that problem before, but perhpas you could try doing what Nirvik suggested above, since it sounds like it’s something to do with the graphics output. He suggested typing the following command in Octave:

Octave can use several different methods to produce its graphical output, so it’s possible that using a different one will not require vc100libtiff-3.dll, which sounds like it’s something to do with producing tiff images. I’ve no idea why it might be missing in your installation though.

Ted

I’ve installed Octave 3.6.4 on Windows 8.

I’ve followed the exact procedure you’ve used for the entire installation. But my plots don’t work. As soon as I hit ‘enter’ after the plot() statement, it goes to the next line but no graph pops up. The Octave window freezes. I’ve even changed the default graphics toolkit to ‘gnuplot’ to try out other options. It doesn’t seem to work.

Hi Calvin,

I’m sorry, but I’m not sure what to suggest. I’m not seeing the problem on my machine, so I’m not sure how to investigate it.

Ted

why after i close Octave this program always show the popup “has stopped working” please help me. sorry for my bad english

Did you type “exit” to close Octave, or did you just click the X button in the top corner to close the window?

Ted

Hi Ted. I was about to be frustrated with Octave’s installation. Your instructions in the webpage are wonderful and was really helpful. I followed your instructions and worked perfect, even with Note++ and the M files (in Windows 8).

Thanks for this great help. Now I can recommend Octave to my students and colleagues.

W. S.

Thanks Walter, I’m glad you found the instructions useful. We have MATLAB on all our School PCs, but I always encourage my students to install Octave on their own laptops and use it as their desktop calculator so that they can get plenty of practice with MATLAB syntax while they’re working on problems in other subjects.

Regarding a good reference on Octave commands, I can’t really suggest one. I normally just refer to MATLAB documentation (either from Mathworks, who publish it, or from third parties). The core syntax is virtually identical between MATLAB and Octave, so any basic MATLAB tutorials should be applicable. Of course, once you start digging into toolbox functions, you’ll find that some are present in Octave and some are not. I presume there’s some kind of documentation available from the Octave web site, but to be honest I’ve never really foudn it useful. If I’m looking for help on a specific command in Octave – say csvread for example – I just google “MATLAB csvread” and hope it will be the same, which is usually is.

Ultimately, I think students are best thinking of Octave and MATLAB as two sides of the same coin. By learning one, you’re also learning the other. There are differences of course (e.g. Simulink), but what you learn in Octave is all stuff you can apply straight away in MATLAB.

Ted

Hello. What is the best reference to learn Octave commands? Is there a book or manual for it?

Thanks.

Where is 3.8.XX version?

Just get it from the Download page on the Octave website.

thanks a lot i have just follow the steps

You’re welcome!

Hi, thank you for your post. I installed octave without any problem and get to this web when I faced the problem that my plots would not show. I realised that you were talking about the solution to put the prompt, and, even that I doesn’t talk about plots, as soon as I put what you said, plots began to work, maybe you should put something about it in that section. By the way, can you explain what are we exactly doing when we add the -i –line-editing text?

Than you so much 🙂

Hi Zeldovich,

I’m glad to hear you found this helpful.

To be honest, I’m not completely sure why those particular command line options work in this case, but here’s how they’re described in the Octave documentation:

It’s a while now since I write this, so I can’t actually remember where I found out to use them, but I suppose I was just googling around trying to solve my problem and I must have come across it being suggested somewhere.

In the case of the “–line-editing” option, I’m assuming that the “readline” they refer to is GNU Readline or something like it. If whatever line editing infrastructure is available on a particular platform isn’t working for Octave, I can see how this might push it to use some kind of built-in line editor instead, which seems to make sense in this particular case.

Ted

Wow! thank you for answering so fast!

First time I am thanking someone for help in computer related topics. Spent the whole day and was about to give up on Octave and than I found your page. It working like charm. Hope it will keep working like this and I can focus on learning the topics for which I am using Octave.

Thanks ejb guy. Hopefully you’ll end up loving Octave as much as I do. You can hit a couple of small roadbumps, like this installation thing, but once you get up and running it’s an absolute lifesaver!

Ted

I am having problem with using notepad++ editor. when i wrote a code and run in octave the command window appears and just stays there.

Updating the shortcut resolved many other plotting issues also

I am having problem installing packages. It shows something like package not found. Can anyone help me?

Man, thank you so much, you made my day!!

I tried many different installations of Octave (Linux virtual machine, Cygwin, etc), which all failed until I tried the one you did, however, if Octave was running fine, plots were not displayed… I spent the day on this and was starting to be sooo desperate!!

I finally found your page and since I had the command prompt missing as well, I did as you said, and tried again to plot , all “who knows?” mode : it miraculously solved the problem!!

Thank you so much!!

You’re welcome! Glad you found it useful.

Ted

I’m new n dont how to solve the differential equation task , can u give some tricks to do? about the steps

Hi Yusuf,

I don’t know much about it myself to be honest. However, you can find some simple examples here:

https://www.gnu.org/software/octave/doc/interpreter/Ordinary-Differential-Equations.html

Ted

Reblogged this on anything and commented:

Octave 3.6.4 Installation on Windows 8.

Thank you for writing this 🙂

You’re welcome!

Ted

Hello, I’m ida.

thank you for sharing. I’d like to re-share your writing.

by the way, why do you prefer Octave 3.6.4 instead of 3.6.2 or 3.8 (or the newest)?

Thanks!

Hi Ida,

As it happens, I’m running version 3.6.4 on my Windows PC and version 3.8.2 on my Linux laptop which is what I use most of the time. To be honest, I haven’t really noticed much that’s different between the two versions, but I tend to work mostly from first principles at the command line (or in M-files) – I rely mostly on core functionality that doesn’t really change from version to version and I don’t use a lot of toolbox functionality. Also, for practical teaching purposes, I try to stick to what works identically in MATLAB and Octave, because we have MATLAB on the school computers but I recommend Octave to my students because it’s really convenient and of course free. My guess is that there have been significant changes in the toolboxes etc over recent versions, but the one big thing which has definitely changed recently is the GUI. A student of mine here in DIT was showing me the new GUI a few months back and I was really amazed to see how polished it looks now. I expect the GUI is front and centre in the new version 4.0 which has recently been released, but I haven’t had a chance to try it yet. Now that the teaching term is coming to an end I hope to spend a bit of time getting up to date!

Ted

Hi,

I have C:\Octave\3.2.2_gcc-4.3.0 with me.I have installed this on windows7.I need work on language processing.As im new to this i need help how to work with this.what packages are required and how to use GUI for the same version of octave.please help me.

Hi Vijay,

If you’re planning to use the GUI interface primarily, you should probably consider Octave version 4.0.0 which is available from octave.org now. I haven’t moved to the new version yet myself, but as far as I know, the GUI is now the primary interface. I think there’s a Windows installer for it too, but I haven’t installed it yet.

Ted

i just installed GNU 4.0.0 on Windows 8. It did give me a warning that GUI is not fully compatible with windows 8 but installed without problem. Looks very close to MATLAB interface now and comes with editor and everything. Great improvement. Looking forward to dig deep into it.

Great, thanks for the info Masood. I’m looking forward to trying it out myself. MATLAB is awsome, but it would be great to have a more complete free substitute.

Ted

One reason why I quit using Gnu Octave was I couldn’t figure out how to do tables. Also, when I did loops I could only preserve the variable values calculated in the last loop and not the values calculated from the other loops. If someone could tell me how to do these techniques, I’d consider coming back to Gnu Octave. Even better, if I could export the results to Excel.

Hi esong98,

When you say that you couldn’t do tables, do you mean you couldn’t print tables? If you just mean you couldn’t create matrices, the syntax is basically exactly the same as in MATLAB. Similarly, the syntax for loops is the same as far as I know. I certainly haven’t noticed anything different between programming loops in MATLAB and Octave.

Regarding exporting results to Excel, what I normally do is write my matrix to a CSV file (comma separated values). This is a standard plain text format for exchanging numerical data between different programs – it can be opened in Excel and lots of other software packages too, so it provides plenty of flexibility.

Here’s an example of creating a 3 x 3 matrix and exporting it to a CSV file which can be opened in Excel:

Hopefully that helps.

Ted

Thanks for your response Ted. I meant I couldn’t print out tables and/or then export them to a latex or excel file. As a beginner I didn’t even know what a CSV file was until I just looked it up on ask.com. So I just create a CSV flle in any plain text file? Then how do I get it displayed in an excel worksheet without having to type in the values manually?

Knowing how to do these procedures would be very helpful to me, because I’m finding out that Visual Basic is a very clumsy vehicle to doing complex mathematical modeling. Even when you declare the variables as doubles or long, it still can’t handle big numbers, and moderately complex calculations causes the program to breakdown. In fact, under certain conditions, excel can handle more complicated calculations than its complementary VBA program.

You have to remember I’m an old guy who learned computer programming by learning Fortran.

Hi again esong98,

The example I gave above is Octave code to create a 3×3 matrix containing the numbers from 1 to 9 as example data, and then write that matrix to a CSV file called “mydata.csv”. That CSV file can be opened in Excel just like a regular Excel document. You should literally see the numbers from 1 to 9 appearing in the first three rows and columns of your Excel spreadsheet.

To open the CSV file in Excel, just click on the “File” menu and then click “Open…” and browse to the folder containing your CSV file. If you don’t see the CSV file in the folder it’s probably just not being displayed because the file extension isn’t “.xls” or “.xlsx” as it would be for a normal Excel document. To fix that, set the filetype to “*.* All files” at the bottom of the File Open dialog box. You should then see your CSV file and you’ll be able to double-click on it.

By the way, if you’re not sure how to run the example code, there are two ways:

1. Run Octave and just type the lines in manually one at a time, or

2. Open a text editor (e.g. Notepad), type in the two lines, and save it as “example.m”. Then, run Octave, change folder to the one where “example.m” is stored and type “example” (without the .m extension!) to run the program.

Either of the above approaches should create the CSV file, “mydata.csv”.

Hope that helps.

Ted

Ted thanks! I’ll try that for my next project.

PS Don’t worry – I’m sure most of what you learned in Fortran is still good to use, even if it’s more likely to be in another language now. My first programming class in college in the 90s was actually in Fortran. As it turned out, I haven’t written a single line of Fortran since then!

Hi Ted,

Thank you very much for your post, it was really helpful!!

I’ve replicated your set of commands in order to plot as well the sinusoidal functio. It appears, but it keeps coming along with these error message: ” ‘gnuplot’ is not recognized as an internal or external command, programme, or archive ; executable”

(The original message reads: ” ‘gnuplot’ no se reconoce como un comando interno o externo, programa o archivo por lotes ejecutable”)

What can be the reason for this?

Thanks a lot!

Max

Hi Max,

Assuming you selected the same options as I did during installation, I’m not sure why gnuplot is not being found. gnuplot is basically an entirely separate software package that is used to create all kinds of plots and graphs. I think it is installed by default when you install Octave on Windows. Here, Octave uses gnuplot behind the scenes to take care of producing plots. However, gnuplot is just one of the packages Octave can use for this purpose, so it might be worth trying a different option since gnuplot doesn’t seem to be available (or at least is not being found correctly) on your PC.

Octave’s “graphics_toolkit” function allows you to check (or set) which graphics toolkit is currently being used to plot graphs. To see which graphics toolkit is currently being used, just type the following command in Octave:

It will probably tell you gnuplot is currently being used. To check which toolkits are available, use the Octave’s “available_graphics_toolkits” function, by typing the following in Octave:

That should print out a list of available toolkits, probably including “gnuplot” and hopefully including one or more other options. If there are other toolkits in the list, you can try selecting them using the “graphics_toolkit” function again. I’m writing this on my Linux machine and the available graphics toolkits are “fltk” and “gnuplot”. To select “fltk” I would type the following in Octave:

Give that a try and see what other toolkits (if any) are available.

Ted

i installed it in my laptop which is windows 8 but after i followed all steps still it is not comming please help me

Hi Srujana,

Is it definitely Octave version 3.6.4 that you installed? These instructions apply to that specific version. If that was the one you installed and you followed the instructions precisely, then you could try installing a newer version of Octave instead since 3.6.4 is no longer the latest version.

Ted

thank u for suggestion

You’re welcome.

Ted

Excellent. Very Good detail, works like a charm

Thanks Tom, I’m glad you found it useful!

Ted

I installed Octave 3.6.4. I am trying to run mvnpdf but its not able to recognize the command. I have clicked to install all the packages. Infact when i do pkg list I can see statistics package there. Can someone suggest pls.

When you installed the pkgs, did you remember to tell Octave to automatically load them? If not, everytime you start it you’ll need to load the pkgs you want to use. Just type “pkg load pkg_name;” without the quotes and you’re done. To make sure the pkg was loaded successfully, just check with pkg list and see if there’s an ” * ” next to the pkg name; you should see something like the following:

pkg load image;

pkg list

-| Package Name | Version | Installation directory

-| ————–+———+———————–

-| image *| 1.0.0 | /home/jwe/octave/image-1.0.0

Hi Ted, after having problems with plotting I reinstalled Octave according to your recommendations. It worked perfectly. Thank you very much and Merry Christmas!

Micha

Thanks Micha, I’m glad to hear you found it useful!

Happy Christmas to you too.

Ted

Hello All,

Is there any chance we can use Octave Plotter for Windows 10 Smart Phones?

Thankyou very much sir you saved my life….

You’re welcome Sahil!

Ted

Thanks a lot! This article proved to be very helpful.

You’re welcome!

Ted

I also have managed to download Octave thanks to your instructions. Only just started using it and following a tutorial. Having a problem when it doesn’t like a command I enter, it just shuts down then I have to reopen it and start all over again. Any tips?

Hi Cindy,

Sorry to hear you’re having that problem. I’m running only Linux on my laptop now, so it’s quite a while since I’ve used Octave in Windows. Did you follow all the instructions in the “Fix for Windows 8” section above? The problem you’re having sounds similar to what would happen if you hadn’t implemented that part.

Also, I googled and there’s a discussion about this problem on Stack Overflow where you might get some useful suggestions:

https://stackoverflow.com/questions/17513864/problems-with-octave-on-windows-8-crashes-after-any-error

Finally, if you’re still using Octave 3.6.4, I suggest trying a newer version. Perhaps the problem will just go away. You can download a binary installer for the latest version from the Octave website:

https://ftp.gnu.org/gnu/octave/windows/

Best of luck. Once you resolve this problem, I hope you’ll find Octave as useful as I do!

Ted