Calling MATLAB or Scilab function from C++ project - c++

I'm trying to access some Scilab functions from my C++ project. I'm working on Windows 7. How can I do that.?
For example,
function [r] = fun(a,b)
r =a+b;
endfunction
How can I tell my C++ project, it should run the Scilab function "fun" and give the parameter a=4, b=9. so that I get their value?
If somebody did this for MATLAB, I think this will be the same here (without using its engine).

A lead would be to use Julia that is quite similar to MATLAB. I'm not sure it's possible yet to compile to a library. The project is based on LLVM so maybe you can generated C code and integrate it with your code.

For MATLAB, you can use the MATLAB compiler, and you should be able find some examples on the MATLAB website.

You will need the Scilab runtime aside, but call_scilab is probably what you are looking for.

Related

Calling MATLAB from C without using Coder?

So I'm currently working on a project where I'm trying to call a MATLAB algorithm from C++ because we're trying to have the final application work on an iOS device.
Is there a way to call that MATLAB code that's been written from C++ without using MATLAB coder?
I've looked into using coder.ExternalDependency class and the official documentation but that uses MATLAB coder and I am trying to avoid that.
I also looked into using feval but all of the examples I could find online were only using pre-built in MATLAB functions like gcd - can I use feval with functions that I wrote myself to call from C++, or do they have to be functions already existing in MATLAB?
Or if anyone has any other suggestions on how to call a MATLAB function in a C++ program that would be great.

CPLEX equivalent C++ of cplexmiqp MATLAB

I have a matlab script, which uses Cplex, to implement in C++. Does the C++ equivalent of the toolbox function cplexmiqp exist ?
If not, how can I solve my problem? I only have the parameters needed to this function to solve the MIP problem (H, f, Aineq, bineq, Aeq, beq, sostype, sosind, soswt, lb, ub, ctype)
cplexmiqp is a convenience function in the CPLEX MATLAB Toolbox API. There is nothing exactly equivalent to this in the C++ API. However, the C++ API is actually more powerful/flexible and you can definitely accomplish the same task. You'll have to build the model using your input data, solve it, and query the solution using methods in the C++ API. I'd suggest that you take a close look at the ilomiqpex1.cpp example that is shipped with CPLEX.

Porting OCTAVE C++ to iOS

i'd been surfing the web for several hours finding always the same sites and no real answer to my query. Here's the thing, i'd like to port some of the Octave functions to a iPad/iPhone app.
i'd already tried to mix C++ with Obj-C and it works like a charm BUT i haven't been able to find the right source of OCTAVE to compile at least the very core of it, i did download the source code from sourceforge.net but i'd had seen some fortran and some other languages classes but not c++ classes.
Does anyone over here had found or had worked with some C++ classes that holds the OCTAVE functions so i can port that to iOS.
Thanks in advance for your time.
Regards,
Jorge.
This may not answer your question, but might help: If the Octave functions you are using are relatively simple, you could try using a linear algebra package such as Armadillo. The docs contain a conversion sheet from Octave/MATLAB to C++.
Check if the functions you need are in Accelerate.framework, it embeds BLAS and it's optimized for each platform.

How to Integrate matlab with Qt on windows 7

I'm stuck in a very important part of my project as i need to call Matlab functions form Qt 4.7.3 since i use the Qt for my interface (UI) and i want to call matlab function that return results and it appears on Qt UI
i searched many and many and i didn't find any thing that can help even with traditional C++
this will get you started. Basically you compile a dll from within Matlab, and call the dll from your c++ code. Note however: it can take a looong time to load the dll since it loads the matlab runtime etc. Also, all computers you want to use it on need the matlab runtime installed.
A newer option is this one. Haven't tried it yet so I cannot comment on it but it looks promising.
See the documentation for calling Matlab from C++. You'll need to visualize the results yourself, if you want to visualize them in Qt.

Call MATLAB APIs in C/C++

I just heard from somewhere that for numerical computation, "MATLAB does offer some user-friendly APIs. If you call these APIs in your C/C++ code, you can speed up computation dramatically."
But I did not find such information in MATLAB documents like http://www.mathworks.com/support/tech-notes/1600/1622.html and http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/bp_kqh7.html. All I learned from these websites is that MATLAB can be called in C and C++ by Matlab engine or by compiling M-files into libraries by mcc. They don't mention any built-in numerical MATLAB APIs that can be called in C/C++.
Can someone please clarify?
Thanks and regards!
You want the "Engine" routines. This allows you to start up a background MATLAB process from C and execute calculations on it: relevant MATLAB documentation.
It works pretty well, have a look at the examples. I would say the most annoying thing getting it working is marshaling the data between C and MATLAB. But that's always a problem when doing this kind of thing.
It sounds like you're looking for the code generation tools in the embedded matlab toolbox or real time workshop.
Do doc eml and look for a the LMS (least mean square) equalizer demo.
The code generator is quite good, it will give you a make file that will build a static library. It's easy to use with your stand alone C/C++ code.
There could be a few things that quote is referencing, I assume that it is referring to the MATLAB Compiler. So going from MATLAB -> C++ you can use the compiler to build standalone "faster" applications. However, when speed testing the improvement, I've noticed it to be negligible. Honestly, you're probably far better off coding your work in C from the get-go, the code that the compiler generates is spaghetti and non-object oriented. I should also mention that this is an expensive extension to Matlab.
You can use the MCR in your own c++ project as a stand-alone library (details)... but you might get similar results using Numerical Recipes.
Disclaimer: I used this product 2-3 years ago, things could be different now.