8

How can I create and debug octave programs in Visual Studio Code? Please provide details regarding Path settings etc.

I'm taking Andrew Ng's course on Machine learning in which he suggests octave as the language for beginners, will octave be useful later on for purposes other than purely academic learning? Can I create machine learning algorithms using octave?

Karmah24
  • 485
  • 1
  • 5
  • 14
  • 2
    Why would you even need to use Visual Studio specifically? Octave comes with an amazing gui IDE out of the box. – Tasos Papastylianou May 23 '20 at 10:47
  • As for whether it's useful, yes, it's very useful, like any language you learn. At the very least it's almost identical to matlab, which is widely used in industry. More generally, vectorization techniques will be used in any language you jump onto in the future, and octave /matlab are probably the easiest languages to learn and understand vectorization in terms of syntax. Obviously you can do machine learning algorithms in octave, as is evident from the fact that Andrew Ng has given you such algorithms. Having said that, there are more popular languages for ML libraries these days. – Tasos Papastylianou May 23 '20 at 10:49
  • 3
    @TasosPapastylianou I wanted to use vscode so that I could use both python an octave simultaneously, makes working a little easier and mostly for the dark theme, coding during night, I find unpleasant otherwise. Is there a way to change the theme in the default GUI? – Karmah24 May 23 '20 at 16:56
  • Yes of course, it's fully configurable like you'd expect from an IDE. – Tasos Papastylianou May 23 '20 at 17:51
  • 2
    @TasosPapastylianou - Octave GUI does not have a dark mode. It only allows you to change a small portion of the background color. – Kyle Delaney Nov 19 '20 at 00:27
  • @KyleDelaney Octave is based on Qt. Just download a dark qt style and select it from the preferences. Adwaita is a nice one. – Tasos Papastylianou Nov 19 '20 at 10:46
  • @TasosPapastylianou - I don't know how to do that. Do you have a link? This is as dark as I can get it using the built-in settings: https://i.imgur.com/5F7dqES.jpg – Kyle Delaney Nov 19 '20 at 17:58
  • @KyleDelaney on ubuntu you can do `sudo apt install adwaita-qt` from the linux terminal, and then in the octave IDE select this theme from Edit -> Preferences -> General -> Interface -> Style -> Adwaita-Dark. Here it is on my PC: https://i.stack.imgur.com/Clxbz.png – Tasos Papastylianou Nov 19 '20 at 20:07
  • @TasosPapastylianou - Do you have any links explaining how to install new QT styles in Windows? My searches for "windows install new qt style" and "install adwaita-qt style windows" have yielded nothing useful. I've only found Adwaita on GitHub, and they expect me to compile it myself. – Kyle Delaney Nov 20 '20 at 18:43
  • @KyleDelaney alas, I'm not a windows user. I would have thought that there would already be a windows dark theme installed somewhere though. Perhaps [this](https://stackoverflow.com/a/54369421/4183191) is relevant? – Tasos Papastylianou Nov 20 '20 at 19:04
  • VS code is superior to octave GUI for debugging. octave has long had issues with losing/missing breakpoints when file is edited/saved, and you cannot assign a breakpoint after Go in case you forgot. There is no stack trace in octave. I can't recommend vs code with octave-cli more highly to anyone who likes octave. – J B Mar 17 '21 at 16:09

3 Answers3

7

Press Cmd+Shift+P (or Ctrl+Shift+P) and search for "Preferences: Open Settings (JSON)". Then add the following entry to the settings file:

"terminal.integrated.env.windows": {
    "PATH": "C:\\Octave\\Octave-5.2.0\\mingw64\\bin"
  }

Then you'll be able to type "octave" in the terminal to access the octave shell

Note: "C:\Octave\Octave-5.2.0\mingw64\bin" is the path where octave is installed for me

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • I know this is an old thread, but following your steps led me to an error that says "Object with environment variables that will be added to the VS Code process to be used by the terminal on Windows. Set to null to delete the environment variable.". I cannot find what I'm doing wrong. – LFSS Feb 18 '22 at 02:02
4

Under settings add this to the terminal shell settings in vscode

"terminal.integrated.shell.windows": "C:\\Octave\\Octave-5.2.0\\mingw64\\bin\\octave-gui.exe"

This is the default installation location . Add the location where you have installed octave.

Karmah24
  • 485
  • 1
  • 5
  • 14
4

VS Code has plugins for working with Octave, available on the VS Code Marketplace.

For running and debugging Octave code inside VS Code, try the Octave Debugger plugin.

For syntax highlighting and file structure recognition, try the Octave plugin from Toasty Technologies or (shameless plug) my own Octave Hacking plugin.

Andrew Janke
  • 23,508
  • 5
  • 56
  • 85
  • How does one make plots show up in VSC? OK got it working by using `octave-gui` instead of `octave-cli` for launcher – Jean Monet Mar 12 '21 at 20:51
  • @Andrew Janke, how to open mlx file? – TeeTracker Dec 05 '21 at 16:08
  • AFAIK, VS Code does not currently support the .mlx file format. (MLX a ZIP file which contains a hierarchy of XML etc files in an undocumented format.) And Octave itself does not support mlx files or Live Scripts, so there's kind of no point in doing that IMHO. – Andrew Janke Dec 07 '21 at 23:24
  • Bit of a noob here but I installed your plugin, and I could not find a way to make VScode recognize octave code. Is there any special install routine that I should follow or is it just a simple plug-and-code? – LFSS Feb 19 '22 at 19:52
  • @LFSS: Hmm. You may need to manually configure your VS Code to treat files with the ".m" extension as Octave code. ".m" is also used for Objective-C code (and Matlab code), and one of your other extensions may be taking precedence there, since it's a more popular language. I should document that better. If you still have trouble, drop by https://github.com/apjanke/vscode-octave-hacking/issues and report it as an issue and we'll get it sorted out. – Andrew Janke Feb 22 '22 at 00:31