How to execute a Matlab function in MS Visual C++? [duplicate] - c++

This question already has answers here:
How to execute a Matlab script from C++
(3 answers)
Closed 3 years ago.
I have 2 separate functions which one is in MS visual C++ and another is in Matlab. How do I execute the Matlab file in MS VISUAL? Is there a windows function to load the .m file and execute it straightly?

Two ways to run Matlab code in C++:
Call MATLAB Engine directly.
The target machine needs to have the MATLAB installed. Check out Call MATLAB Functions from C and C++ Applications for more info and examples.
Distribute MATLAB code into independent shared library (dlls).
The target machine needs to have the MATLAB compiler runtime. Check out here on how to do this (with detail steps and example).

Related

How Do You Compile C++ Code Using Vim (Windows)? [duplicate]

This question already has answers here:
How to Compile C++ Code Using Vim on Windows?
(2 answers)
Compiling and Running a C++ Program with Vim [duplicate]
(3 answers)
How do i compile and run a c++ code in vim (windows) [closed]
(3 answers)
How to compile a cpp file directly from vim editor in Windows?
(1 answer)
Closed 11 months ago.
So I've been searching for literally hours but I can't find a good way to compile my C++ codes through GVIM. So I've tried to compile my programs through Window's Command Prompt, but it didn't work out too well because I had to move my files around, which I didn't enjoy at all. I also tried using the :make function in GVIM which for some reason also didn't work. So can someone please just give a detailed instruction on how I can run my C++ codes while using VIM? Thanks!
P.S. There's a YouTuber that I watch and this was what I meant when I was wondering about compiling code: https://www.youtube.com/watch?v=uGrBHohIgQY << Fast Forward to 1:20
Did you make own Makefile? :make will work only when you have created that file.

Mac - c++ - create file.exe [duplicate]

This question already has answers here:
Clang C++ Cross Compiler - Generating Windows Executable from Mac OS X
(3 answers)
Closed 5 years ago.
I've write a c++ project using xcode on a mac.
What I need is to create a .exe file to run the project on windows in anothre pc (no virtualization).
I've read that xcode doesn't provide this service and so I've tried to compile it also in Eclipse (on mac) but I'm not able to get the .exe file.
Is it possible, on mac, to generate a .exe of a c++ project runnable on windows?
Thank you
Yes, it is possible and it's known as cross-compilation. Besides building your own toolchain for doing this, you can use MinGW: Cross compiling with MinGW

How to run a C++ code in Matlab [duplicate]

This question already has answers here:
Call C++ code from MATLAB?
(4 answers)
Closed 8 years ago.
I have codes which are written in C++ and I would like to use them in Matlab. In my folder I have these files:
do_it.cpp
hist (I guess it's a binary file)
hist_lebesgue.cpp
hist_lebesgue.hpp
tools.cpp
tools.hpp
The program is supposed to make a pdf distribution of your data set.
I was told that to run the code in Linux (I guess by C++ compiler) you need to call the binary 'hist' from the linux commandline. If you are in the
folder where the binary lies then you need to type for example
['./hist 1000 2 path_to_file'].
path_to_file is the path of your data file.
Now I want to use this code to run it in Matlab. Could someone please help me how I can do this. What should I type in Matlab's command Window?
PS. I am using mac.
Assuming you use Windows OS X: You can't run a Linux executable on Windows OS X. You have two options:
Compile the program for Windows OS X with the MinGW OS X version of gcc / g++.
If that doesn't work, or you find it too difficult: Install Linux (e.g. Debian) in a virtual machine (e.g. VirtualBox), and install the Linux version of Matlab in it.
EDIT: Once you have installed the compiler on your system (I trust you can find tutorials for that with Google), you could try this command for compiling the program:
g++ hist_lebesgue.cpp tools.cpp do_it.cpp -o hist
I can't promise it will work though, since I don't know the source code and can only guess how to compile it. You should ask the person who gave you the source code for instructions how to compile it.

Integrate MATLAB code in Visual Studio 2010 (C++)

I've seen that it is possible to call MATLAB functions from VS2010 (VC++). I was wondering if it is possible to create executable files using VC++ that do not require any MATLAB software on the computer (like the MATLAB Compiler Runtime (MCR))?
I would like to create a program written in VC++ that calls some of the MATLAB functions, but is completely standalone and can run from any Windows computer without the need of any prior MATLAB software to have been installed.
Thanks.
It is not possible to install without MCR in any documented way and I even think that it is not legal.
However, there are some examples like Imatest, who managed to do it in some of their earlier versions.
Edit(1)
I almost forgot about MatlabCoder. If you buy it, it can transform your Matlab code directly into c code. But it will not work with some of the toolboxes, like image processing.

Converting Matlab to C++

I need to convert some MATLAB code to C++. I am using Visual Studio 2010 and have MATLAB compiler installed. I am wondering how do I go about doing this.
Also when I publish my project will the end user have to install anything by MATLAB? (this cannot be the case)
You can compile Matlab scripts into standalone executables, but I'm not familiar with a Matlab tool to convert Matlab code to Visual C++ code. You can convert Matlab code to C or C++ using Simulink Coder (formerly Real-Time Workshop), which is available from Mathworks as a separate product.
To run the standalone executable, the user will have to install the Matlab Compiler Runtime. From the Matlab Compiler web page:
Executables and libraries created with the MATLAB Compiler product use a runtime engine called the MATLAB Compiler Runtime (MCR). The MCR is provided with MATLAB Compiler for distribution with your application and can be deployed royalty-free.
You will not get rid of the Matlab runtimes. I often had problems using Matlab Compiler. It basically is like a wrapper around the Matlab runtime, generates clumsy code and did introduce many problems for deployment. C alternatives ... ? I could not find any. So I recently switched to ilnumerics, which is like Matlab in C# - only much faster and no translation necessary. it works out great so far because we use ASP.NET anyway and hence save jumping between languages and can directly use the 3d plots of ilnumerics.
Another option you have is to use the MATLAB Engine. It probably isn't an option for real-time applications, but otherwise it's really nice. You basically call MATLAB functions right from C++. Figures (plots) will be display just as if you were running local MATLAB. When the program starts, a MATLAB console is created.