help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to call a octave function from c code


From: Kai Torben Ohlhus
Subject: Re: how to call a octave function from c code
Date: Tue, 7 Jan 2014 00:24:33 +0100

On Mon, Jan 6, 2014 at 3:01 PM, osamahameed <address@hidden> wrote:
can anybody please write a C code mex file???



--
View this message in context: http://octave.1599824.n4.nabble.com/how-to-call-a-octave-function-from-c-code-tp4660666p4660701.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave

Hi osamahameed,

I think this is what you are looking for: https://www.gnu.org/software/octave/doc/interpreter/Calling-Other-Functions-in-Mex_002dFiles.html#Calling-Other-Functions-in-Mex_002dFiles 

--------------------------------------------------
File: myMex.c
--------------------------------------------------
#include "mex.h"

void
mexFunction (int nlhs, mxArray* plhs[],
             int nrhs, const mxArray* prhs[])
{
  mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);

  if (nrhs != 2 || nlhs != 1)
    mexErrMsgTxt ("Invalid function call.");

  mexCallMATLAB (nlhs, plhs, nrhs, (mxArray*) prhs, "addition");
}
--------------------------------------------------


--------------------------------------------------
File: addition.m
--------------------------------------------------
function [ z ] = addition (x, y)
  z = x + y;
end
--------------------------------------------------

>> mkoctfile -mex myMex.c
>> result = myMex (1, 2)
I have 2 inputs and 1 outputs
result =  3

HTH,
Kai

reply via email to

[Prev in Thread] Current Thread [Next in Thread]