Anni_housie
Anni_housie

Reputation: 489

How can I import a function of Octave to MATLAB?

I am running my code in Matlab. But I also want to call a function in octave. How should I import the qp function of Octave to Matlab?

Upvotes: 1

Views: 510

Answers (3)

carandraug
carandraug

Reputation: 13091

The Octave language is a superset of the Matlab language. If qp only made use of the Matlab language, then you could simply add it to your Matlab path and be done with it.

However, Octave's qp makes extensive use of Octave only language so you basically have to port the code yourself. There are no tools for this, you have to convert the code from one language to another. In addition, the actual solver is the function __qp__ which is written in C++ and uses liboctave. Two easier alternatives than porting qp are:

  • save the data from your Matlab session into a file save foo.mat mydata, call Octave to do the work and save the results system ('octave --eval ''load ("foo.mat"); qp (...); save foo.mat ...;', and read the file back load foo.mat.

  • or the much simpler alternative, just use Octave.

Upvotes: 3

rahnema1
rahnema1

Reputation: 15837

Octave syntaxt is not totally compatible with MATLAB. For example the preferred syntax for defining function in Octave is like this:

function ret =  f()
    %do something
endfunction

but MATLAB doesn't accept that syntax and there are other differences like differences in calling native codes and ... so it is not simple to convert each statement of octave library to matlab or convert oct c++ source to mex.
A straightforward way is that you should have an installation of Octave and run octave script from it then save the results to a mat file and in MATLAB load the file . You may use system function to execute octave or run it from shell.

Upvotes: 1

kpie
kpie

Reputation: 11100

so lets say you have 2 files in the same directory. a.m and b.m In the script b.m if you type a as a line of code everything in a.m will happen (variable assignments function definitions computations etc...)

Additionally you can use the import statement for adding things to your import list. as seen here.

Upvotes: -3

Related Questions