Mex binaries not loaded - matlab

I am trying to use this software available at http://www.cmap.polytechnique.fr/~aspremon/ZIP/COVSEL.zip. They have a function spmlcdvec defined in a matlab file spmlcdvec.m. It further calls a function BoxQP for which they have provided a binary mex file called BoxQP.mexmac. However, when I run the function spmlcdvec it says
Undefined function 'BoxQP' for input arguments of type 'double'.
What should I do? Whats going wrong?

Run mexext in your command window. If it does not return mexmac (or mexw32 which is also present in the folder) then you you won't be able to run the BoxQP function. These are simply old files - I see that they're from 2006. If you're using any form of OS X these days you'll get mexmaci64, which is not compatible. However, it looks like they have helpfully included all of the source code so you'll be able to hopefully compile the binaries for your system. For details on compiling mex code see this.
Then, as #alrikai suggests, your BoxQP function needs to be on your path. Either make sure that you call your code from the same folder or run path from the command window and check if that directory has been properly added (if you did so). See also addpath.

Related

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).

Matlab, Mex files, undefined functions

It may seem like this question has been asked already, but after several days of dealing with this problem and searching for solutions, I am coming up empty. To begin, I am using matlab2012a
So I have the mexa64 file compiled, let's call it foo.mexa64 . My computer can handle 64 bit (matlab >>computer, returns GLNXA64). I have added the folder that foo.mexa64 is in to the path using the pathtool. I did this when I opened matlab, so the changes are there. This is also not in the root/toolbox folder, it is saved in my Documents/MATLAB.../fooDirectory folder.
I can run these mex files in the command line in a different directory and everything works fine. However I cannot call them in a function, I get the "Undefined function 'foo' for input arguments of type 'double'" error.
Using the 'which foo' function returns the path:
home/.../Documents/MATLAB/.../fooDirectory/foo.mexa64
'help foo' returns
foo not found
To check, I created a dummy.m file in the fooDirectory folder. This function can be run in other functions outside of the directory with no issue.
If you need anything else, please let me know, I am completely at a loss!

mat2gray function does not work when called from Perl

I have a script in perl that generates a .m file based on a series of parameters and then runs an octave algorithm through ticks like:
`octave my_script`;
And then I capture the results in a separate file. The problem is that even having installed the image package succesfuly mat2gray function is not working.
If I open manually octave like a separate console to be used manually, and call my script it does work perfectly. The issue appears only when calling the octave.exe from Perl. It shows:
error: `mat2gray' undefined near line 21 column 6
Which looks like the typical error you get when you don't have the image package (and I do have it installed and I'm able to usethe function on octave console directly). I already tried to iclude a line on my script at the very top to rebuild the package everytime my script runs, like so:
pkg rebuild -auto image;
But that didn't fix it. Anyone has seen this kind of odd behavior?
I'm using Octave 3.2.4, since I need that version due to some compatibility issues with other pieces of software that we need. And some plotting capabilities when called from perl don't work all that well. Just in case you were wondering.
For future reference, I replied to the question here.

How to make matlab see functions defined in .m files?

I'm a total newbie to MATLAB but I have to write some code in it. I've had problems with making MATLAB see functions I've defined in external .m files. This is what I've done: I've created a file named, say, foo.m in my home dir with the following contents:
function [y] = foo(x)
% description
y = x + 1
When I run matlab (my home dir is matlab's workdir) it does not see foo function - it replies with standard ??? Undefined function or variable 'foo' message. BUT help foo or which foo return correct data printing help text and pointing on foo.m file respectively.
I must be missing something but I have no idea what it is. This is getting very annoying.
Oh, after several trial and error attempts I've managed to call that function. Unfortunately I can't remember the sequence of steps I've performed. Moreover after restarting matlab it returns to its usual 'Undefined function or variable' response.
I have 7.11.0.584 matlab running on linux.
MATLAB needs to be told which directories to search over to access those m-files. Clearly it cannot be left to search over your entire disk drives. The MATLAB search path is a list of directories that will be searched in specific order to find your functions.
help addpath
help pathtool
You should never put those files anywhere in the official MATLAB toolbox directories. Choose an entirely separate directory.
Finally, be careful not to name your own functions to match the names of existing MATLAB functions. Otherwise, your very next question here will be why your code does not work properly. This is a common cause of strange and confusing bugs.
It seems you're having some trouble with addpath. Try opening the file in the matlab editor and adding a break point in the file. If the file is not on Matlab's path, matlab should ask if you want to change directory or add the file to the path, choose add to the path.
If this doesn't work, try changing the current working directory (displayed in the main window) to the same location as the m file and calling the function. If this doesn't work you're either getting the name wrong ar there's possibly something wrong with your installation.
Occasionally matlab has problems if it does not have write permission to the directory the file's in, so check that too, i.e. make sure admin rights aren't required for the directory or m file.
Oh, and try:
clear functions
to reload all functions into memory.
The function needs to be in MATLAB's path. Use pathtool to tell MATLAB where to find your function. Note that if you name a function the same name as an existing function, MATLAB will use whichever function it finds first according to the order that the paths are listed as you see them in pathtool.
Although coming late but I hope it will help someone.
If in the folder where the function you are calling is residing, there is any other function with the same name as one of the functions from MATLAB toolboxes, then Matlab will not recognize its license and therefore will disable the whole folder from execution, no matter it is properly added to the path. The help will display though.
In order to check it, type:
which name_of_func.m
and you will get the path with "%Has no license available" message.
If it is your own function, you should not get this message but only the path.
Therefore, find the function in this folder which has the same name as a MATLAB toolbox functions, and rename it. I will solve the problem :).
Best Regards
Wajahat

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.