Skip to main content
Library homepage
 
Engineering LibreTexts

6.1.1: Octave vs. MATLAB--not equal, end, endif, endfunction

  • Page ID
    86604
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

     

      Here are some codes that Octave allows, but which are not compatible in MATLAB.

      Octave users should use MATLAB compatible code, so that their code can run in either Octave or MATLAB

      1. In MATLAB, the not equal symbol is ~=. Octave allows either ~= or !=

      2. In MATLAB, a function should end with the keyword "end". Octave allows either "end" or "endfunction". By default, Octave inserts "endfunction".

      3. In MATLAB, an if logic block of code must end with the keyword "end". Octave allows either "end" or "endif". By default, Octave inserts "endif".You change Octave's default to “end” by doing the following:

      From the main window’s top menu bar, click on “editor”, then click on “Preferences”, which is the last in the list of options.
      In the preferences window, change ‘Auto insert after “if” etc.’ from endif to end. Then click Okay.

      clipboard_e76a057075ac94e0c6e93a82479b9685e.png

      .


      This page titled 6.1.1: Octave vs. MATLAB--not equal, end, endif, endfunction is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith.

      • Was this article helpful?