Is there anyway to make an executable compatible by using matlab mex? - matlab

The executable is created by using mex. Currently I tried it on windows, but eventually I will need it for windows, linux, and mac os x.
The problem is it can only be used with the same version of matlab which I used to create it.
The main reason I think is if different version of matlab is used, then the path for libraries used by the executable will be different.
Is there any way that I can create an executable from mex which can be compatible with different versions of matlab?
Is possible that I set paths for libraries and header files associated with multiple versions of matlab?
Please correct me if I understand anything wrong above. Thanks a lot.
More detail information:
The way to generate my executable is to call:
mex('-v', '-f', [matlabroot '\bin\win32\mexopts\msvc90engmatopts.bat'], 'myexecutable.cpp');
In the msvc90engmatopts.bat file, paths are set for librarires and header files and etc.
msvc90engmatopts.bat is from matlab.

Related

Where are matlab files stored which are given in documentation for trying out in browser

I have used try in browser features in matlab to run some code which are the part of documentation provided by matlab.
To explain this more simple, here is the link which lets users to try the matlab in browser.
I am trying to see those matlab files ( object3d.mat) in this case. But I cannot find any information about where are those files.
Is there anyway to download that file ('object3d.mat) ?
These mat-files come with MATLAB installation. If the MATLAB directory (including all sub-directories and files) is in your path (by default, it is) then you can use load to load it into your workspace i.e.
load object3d.mat
%or just: load object3d
If it is in your path, you can know its location using which i.e.
>> which object3d.mat
C:\Program Files\MATLAB\R2018a\toolbox\vision\visiondata\object3d.mat
>>
Note: Please make sure that you're reading the documentation of your installed MATLAB version and have the specific toolbox installed. If the documentation for the MATLAB version that you're using doesn't include that filename then it is likely that it is not available in that version.

How can i copy m-files to a specific folder in MATLAB compiled application?

I'm using MATLAB R2015a application compiler. After choosing my main m-file, MATLAB found some files required for application to run but after compiling and running my application, the compiled application can't find some specific m-files from an installed toolbox (third-party toolbox).
Now i want copy all toolbox files to target folder C:\Users\My_Account\AppData\Local\Temp\My_Account\mcrCache8.5\Program_70\DDM. DDM is my toolbox folder that MATLAB creating it automatically based on nested files as mentioned above. I want add other files to this folder. How can I do this? and is this a good solution to fix this problem?
What you're trying to do won't work.
When you compile an application with MATLAB Compiler, it finds all code that your main function depends on, encrypts it, and packages it into an executable that will later be executed against the MATLAB Compiler Runtime (MCR).
The MCR can only execute code that has been encrypted and packaged in this way - it is not possible to get it to execute a regular unencrypted MATLAB file. So dumping things into the temp folder that the MCR uses to unpackage code files will not achieve anything.
Instead try to figure out why, during the dependency analysis, MATLAB Compiler is not finding all the files that your main function depends on.
There are various reasons why that might happen - the dependency analysis is not perfect. For example, if your code calls eval('myfunction'), the dependency analysis will not find myfunction. I answered another question recently where another cause was the issue.
In these situations you can explicitly tell MATLAB Compiler that there is a dependency on myfunction, using the %#function pragma. Within the file that contains the hidden call to myfunction, at the top of the file (actually anywhere, but typically you'd put it at the top), put
%#function myfunction
MATLAB Compiler will then force that to be a dependency and include it in the packaging.
Alternatively, when setting up the packaging with mcc or in the deploytool app, you can just manually add myfunction to the package yourself (although this will then not find things that myfunction depends on).

How to create mex file in matlab having just object file, without source?

I have a precompiled static library propa64.a, which i want to use in Matlab in Linux.
No source code of it available, only header file (propa.h). As far as i understand, to use it in Matlab i need to create mex file. How can i do it, without source and with only compiled propa64.a?
mex propa64.a
doesn't work, matlab says "mex: no filename given" error.
Any suggestions?
Or , may be it's possible to use pre-compiled static library in Matlab somehow else?

Matlab and addpath

I have recently been working with Matlab. My question stems from my usage over a few months and is something that I can't seem to solve. I have an external SVM toolbox (OSU-SVM) that I would like to interface to with my project. I am able to get the entire system to work when I add the path of the toolbox manually (Right click -> Add to Path -> Selected Folders and Subfolders). What I would like to do is add the folder in a script. I've tried the "addpath" command but for some reason I can't get it to find the library relative to the m-file (script) that I run the command from. The following is an example of the code:
% Add OSU SVM system
addpath(genpath('./osu-svm/'));
The reason the I'd like to add the path using a relative folder to the M-file is that the code needs to run in a different environment that will not have the toolbox install. The code is also going to be executed in a different OS to the one I am developing on. That is, I am running a Windows Matlab to develop the code and need to run the finished system on a Linux machine. The process of running my files needs to be as painless as possible and shouldn't require much input from the user. That is why I'm specifically trying to avoid manual addition of the path.
On a side note a similar problem occurs when I wish to use "uigetfile" using a relative path. I believe there is something I am missing that will help me solve both of these simultaneously. Any help would be greatly appreciated.
Instead of './osu-svm/' alone use
fullfile('.','osu-svm')
The reason it does not work for you on windows is that you are using forward slash file separators. Full file will make a file string containing the correct file separator for each OS.
The genpath example in the matlab documentation also uses fullfile
http://www.mathworks.co.uk/help/techdoc/ref/genpath.html
Furthermore, the '.' is kinda unnecessary as it just means "relative to the current directory" and can be left out of the command. Perhaps you meant one directory up?
'..'
???

How to create an executable .exe file from a .m file

I was wondering if there is a way to create a '.exe' file from ' .m' file in MATLAB, such that it can be run in machine which does not have MATLAB (like it can be done in C, C++).
I know writing a MATLAB function is one way, but I am not sure if it can run in machine without MATLAB.
Also I would like to hide my code and just create a script which can be run by a user using his own data files.
The Matlab Compiler is the standard way to do this. mcc is the command. The Matlab Runtime is required to run the programs; I'm not sure if it can be directly integrated with the executable or not.
If you have MATLAB Compiler installed, there's a GUI option for compiling. Try entering
deploytool
in the command line. Mathworks does a pretty good job documenting how to use it in this video tutorial: http://www.mathworks.com/products/demos/compiler/deploytool/index.html
Also, if you want to include user input such as choosing a file or directory, look into
uigetfile % or uigetdir if you need every file in a directory
for use in conjunction with
guide
Try:
mcc -m yourfile
Also see help mcc
If your code is more of a data analysis routine (vs. visualization / GUI), try GNU Octave. It's free and many of its functions are compatible with MATLAB. (Not 100% but maybe 99.5%.)
mcc -?
explains that the syntax to make *.exe (Standalone Application) with *.m is:
mcc -m <matlabFile.m>
For example:
mcc -m file.m
will create file.exe in the curent directory.
It used to be possible to compile Matlab to C with older versions of Matlab. Check out other tools that Matlab comes with.
Newest Matlab code can be exported as a Java's jar or a .Net Dll, etc. You can then write an executable against that library - it will be obfuscated by the way. The users will have to install a freely available Matlab Runtime.
Like others mentioned, mcc / mcc.exe is what you want to convert matlab code to C code.
The "StandAlone" method to compile .m file (or files) requires a set of Matlab published library (.dll) files on a target (non-Matlab) platform to allow execution of the compiler generated .exe.
Check MATLAB main site for their compiler products and their limitations.
I developed a non-matlab software for direct compilation of m-files (TMC Compiler). This is an open-source converter of m-files projects to C. The compiler produces the C code that may be linked with provided open-source run-time library to produce a stand-alone application. The library implements a set of build-in functions; the linear-algebra operations use LAPACK code. It is possible to expand the set of the build-in functions by custom implementation as described in the documentation.