Call MATLAB function octave Mex from Kotlin

Submitted by Dickens A S on Thu, 11/28/2019 - 09:06

Is one of the popular Scientific Programming Language or platform

general MATLAB functions will work in Octave

This Article explains how to trigger Mex script from Kotlin using "mex.h" and "octave.h" C API in Kotlin

Octave 5.1.0 is installed in C:\octave with below structure and files

Note: Octave 6.x.x has C++ class will not support Kotlin, Please use Octave 5.1.0

C:\octave
C:\octave\mingw64
C:\octave\mingw64\liboctinterp-7.dll
C:\octave\mingw64\include\octave-5.1.0\octave
C:\octave\mingw64\lib\octave\5.1.0

To execute the kotlin code and the app

launch the Octave MSYS2 terminal using

C:\octave\msys2_shell.cmd

export the mingw bin path as shown below

export PATH=$PATH:/mingw64/bin

 

Kotlin Code

package plot

import octave.*
import kotlin.math.*
import kotlinx.cinterop.*
import platform.posix.*

fun main() {

    println("Example app to call octave from kotlin")
    
    octave_main(0,null,1)
    mexPrintf("Hello, World!\n");
    
}

 

Sample Output

$ ./build/bin/libgnuplot/releaseExecutable/koct.exe
Example app to call octave from kotlin
Hello, World!

GitHub: https://github.com/dickensas/kotlin-gradle-templates/tree/master/embed-octave

 

Add new comment