File Exchange

image thumbnail

Is this MATLAB or Octave?

version (509 Bytes) by ioxv.4623
Crude but effective tests of whether code is executed in matlab or octave.

1 Download

Updated 23 Apr 2009

View License

UIMATLAB returns true if the function is called from matlab, and false otherwise.

UIOCTAVE returns true if the function is called from octave, and false otherwise.

Using these functions, one is able to execute different parts of the code depending on what engine is performing the operations. Compatibility issues between MATLAB and Octave can thus be avoided.

For example:

if uimatlab
disp('This is MATLAB.')
elseif uioctave
disp('This is Octave.')
disp('I do not know what user environment this is.')

Cite As

ioxv.4623 (2020). Is this MATLAB or Octave? (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

hi there...basic question: I have lot of octave codes (my thesis). Can I efficiently turn it into matlab (at least at a main proportion, then I would refine manually).?????? Pls helps me!! best regards


You can also use switch with string cases.

I like this approach, because the alternative only checks if Octave is running the show, so if there is any Matlab alternative that runs the code, it will assume Matlab is running. Although I guess the chances of another mostly compatible alternative being developed are negligible for any foreseeable future.


Hi Rody:
apologies for the super late reply. Reason I didn't implement it like you suggested is that you then need a strcmp in your if ...elseif...else...end thing, whereas now each function returns true or false directly. Anyway, the difference is minor of course.
Have a good one,

Exactly what I was looking for, a nice trick indeed!

But I wondered...why didn't you put this in a single function? Like

function type = determineUI

where type = 'matlab' if matlab, type = 'octave' if octave or something similar. That would be much more useful in most implementations...

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux