How can I determine if I'm running on a 32bit or a 64bit version of matlab?
I have some pre-compiled mex-files which need different path's depending on 32/64bit matlab.
The question of 32 vs. 64 bits is really a red herring. If I understand correctly, you want to determine which set of compiled MEX files are needed so you can set the path appropriately. For this, you can use the function mexext:
>> help mexext
MEXEXT MEX filename extension for this platform, or all platforms.
EXT = MEXEXT returns the MEX-file name extension for the current
platform.
ALLEXT = MEXEXT('all') returns a struct with fields 'arch' and 'ext'
describing MEX-file name extensions for all platforms.
There is a script named mexext.bat on Windows and mexext.sh on UNIX
that is intended to be used outside MATLAB in makefiles or scripts. Use
that script instead of explicitly specifying the MEX-file extension in
a makefile or script. The script is located in $MATLAB\bin.
See also MEX, MEXDEBUG.
Taking up on ScottieT812 and dwj suggestions, I post my own solution to earn some points.
The function computer returns the architecture I'm running on. so:
switch computer
case 'GLNX86'
display('32-bit stuff')
case 'GLNXA64'
display('64-bit stuff')
otherwise
display('Not supported')
end
works for me
Does this really work? Which version of matlab are you using?
As far as I'm aware the 64 bit platforms end with "64" not 86. From the matlab site
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.html I don't think that computer will ever return GLNXA86 but GLNXA64 instead.
So this question is specific to GNU Linux 32bit or 64bit version.
If you are testing for any 64bit platform then you probably need to test the last 2 characters to find "64" i.e. something like
if regexp(computer,'..$','match','64'),
% setup 64bit options
else,
% 32bit options
end
Related
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.
In my code, I have some compiled mex files. For compatibility reasons, I also have "plain" matlab code that returns the same things.
The idea is that if the user don't have the right version of the mex files, the code should still be able to run with the plain matlab version. It will be slower, but it should run.
The advantage is that matlab will automatically choose the plain matlab version if the right mex file is not present.
Now, my question si the following : is it possible to tell matlab to use, at some point, the "plain" version, even if the right mex file is present ? This is mostly for performances comparaisons.
Thanks a lot for your help,
Environment:
Matlab R2012a (I have access to others if necessary)
All Toolboxes/Compiler installed
Ubuntu 12.04 64bit and/or Windows 7 64bit
I am working with the source for a software package written in Matlab (unfortunately its proprietary so no code examples...sorry), and one function briefly uses the Control System Toolbox and the Signal Processing Toolbox.
I have no problem running the code on my personal computer because I have every toolbox installed, however I would like to compile (mex or mcc) JUST the function using those two toolboxes. The goal, of course, is to run the software on a machine without those toolboxes, while leaving the remaining code open to change.
According to matlab, they have no problem with you compiling code that uses almost any toolbox. Here is the list of toolboxes that support mcc compilation:
http://www.mathworks.com/products/compiler/supported/compiler_support.html
The problem arises in that mcc no longer allows compiling with the -x option to create a mex-ed version of the function, so I'm forced to create a C executable (maybe? hopefully not). This particular function takes large matrices as parameters (impractical to write as a command line argument) and returns a structure of cell arrays.
The only way around this (as I see it now) would be to write the arguments (large matrices) to the hard drive in a binary .mat file , have the compiled C binary read in the arguments, run the algorithm, and finally save the return values in another .mat for the parent thread to load back into memory.
This seems totally impractical. I would greatly appreciate alternative suggestions. Please let me know if anything here in unclear. Thanks in advance!
[Edit 1] The codegen package does not support tf.m. It seems like this should be possible (and used to be possible with the mex -x option), but I'm at a loss. Any suggestions would be greatly appreciated!
I think the reason -x is not supported anymore is the fact that Matlab now has a product called "coder", which converts .m files to .c files and can also create .mex files from "suitable" .m files using the option -args to specify the input arguments: http://www.mathworks.com/videos/generating-c-code-from-matlab-code-68964.html
I try to write matlab mex code with Cuda integrated but it is just hard enough to compile and debug all around. Is there any better approach to code and test? I am on Matlab 2012b.
Currently I am writing code in sublime then compile it on matlab but I am also newbie at CUDA as well thus it is just hard to code it without seeing the result instantly.
The comment by Robert Crovella is interesting.
I just wanted to mention the way I was used to compile mex file with CUDA instructions (and which works also on different versions of MATLAB).
1) Compile by nvcc and transform the source code in C++ code by the command
system(sprintf('nvcc -I"%s/extern/include" -cuda "mex-fun.cu" -output-file "mexfun.cpp"', matlabroot));
2) Link it to Matlab by
mex -I/opt/cuda/include -L/opt/cuda/lib -lcudart mex-fun.cpp
This was originally suggested at the MATLAB Newsreader page.
I have both a matlab entry point (i.e. a file with the function "mexFunction") and a C++ entry point (a file with "main"), and the rest of my actual CUDA code is independant of what entry point was used.
This way, I can debug the code used for my MEX files using the standard set of CUDA tools (i.e. nvprof, cuda-memcheck, etc) without having to deal with the MEX file. Then once I'm sure I have no bugs or memory leaks, I just compile it to a MEX file. Alternately you can always just attach cuda-gdb to your MEX file, although your mileage may vary with this.
I am working on Matlab R2011a student edition. I want to run some demos provided in Matlab which require some toolbox like Embedded Coder and EDA Simulator Link.
I want to check if those toolboxes are installed in my current version of matlab and if yes how can I check if the licenses are valid.
The reference to this link didn't help me:
How would one check for installed MATLAB toolboxes in a script/function? because I need at least the short name of those toolboxes like "control" states for "Control System Toolbox" by using the command ver control.
Any suggestion...
To check that the toolbox is installed, use
v = ver;
any(strcmp(toolboxName, {v.Name}))
where toolboxName is the name of the toolbox you want to check.
To check that the licence is valid, use
license('test', toolboxName)
easily use ver command. it will list all installed toolboxes and their versions. the other way is to check from the start button.
Also you can use the existing function in FileExchange called isToolboxAvailable. The usage is as follows:
result = isToolboxAvailable('image processing toolbox','error');
you can always check out the main help documentation which generally lists the toolbox.
Or if you press "Start" (the Matlab start, not Windows) the list of installed toolboxes will be organised by category
Here is a dirty solution:
try
<funktion from specific toolbox>
<do this if it is available>
catch
<do this if it is not
end
The names of the toolboxes that are returned by the license function are the same as what is in the license file. The license file will either be on the local PC or on a FLEXlm license server, depending on your environment. On Windows, check in C:\Program Files\MATLAB\R2011a\licenses for a license file, which is typically named something like license.lic or network.lic. Open the file in your favorite editor (notepad will do). If you see text that says SERVER followed by a hostname, MAC address, and port number, then you're using a network license and you'll have to ask your systems administrator. Otherwise, there should be an INCREMENT line for each licensed product and the name of the product as used by the license function is given following the INCREMENT keyword. If you're on a UNIX or Linux system, you may have to dig around a bit to find the path for the license file (or perhaps someone else can provide this?).
Edit: My MATLAB install is in a non-standard path. Changed instructions to give the default path.
Just in case somebody stumbles upon this in 2022. There are now several built-in add-on utilities to check if add-ons are installed. Notably:
matlab.addons.installedAddons: Will list all installed add-ons with (long) Name, Version, Identifier (aka short name/hash)
matlab.addons.isAddonEnabled: To check if a given add-on is enabled