Menu
  • HOME
  • TAGS

Profile mex function in visual studio

visual-studio-2010,matlab,mex

You sure can. Just enable generation of debug info (symbols) when building the MEX file, and attach to MATLAB.exe from the Analyze->Profile menu in Visual Studio. It's nearly the same procedure as for debugging MEX files with Visual Studio. The process is trivial if you built the MEX file with...

C++ to mex file: output of system command gets suppressed

c++,matlab,mex

std::system will start the system's command processor to execute the command. If you have a console app, this will print the output to the current console. This is why you see it in your test program. The output is not passed to the calling program! In your case, Matlab seems...

Visual Studio 2012 pro and Matlab 2013a

matlab,visual-studio-2012,simulink,mex

This is a known bug (I'm guessing). See the workaround on the MathWorks website: http://www.mathworks.co.uk/support/bugreports/931218...

Pseudo-random number generation in MEX C

c,matlab,random,mex,standard-library

MEX-files are shared libraries (with a special entry function mexFunction) that are dynamically loaded by MATLAB when executed. They remain loaded in memory unless you clear them. Example: Initially the MEX-file is not loaded (ignore this other MEX-file from another toolbox): >> [~,X] = inmem('-completenames') X = 'C:\Program Files\MATLAB\R2014a\toolbox\slvnv\reqmgt\reqmgt.mexw64' Now...

How to install SPAMS toolbox in Matlab 2014b under windows 8.1

c++,matlab,mex

Hmm. Compiling this toolbox is a bit tricky. Here is how I do it in Windows 7 + MATLAB 2013a. Hope it works for you. (I don't have the issue of unzip) First, you want to make sure that 'mex' works properly, I have compiled some smaller packages and they...

Error using mex (line 206) Unable to complete successfully

matlab,mex,lnk2019,lnk2001

The package you are trying to compile consists of three cpp files, but they should be compiled into a single mex file. as a result they only have one mexFunction symbol defined in them. Try >> mex -O -largeArrayDims Coarse2FineTwoFrames.cpp GaussianPyramid.cpp OpticalFlow.cpp ...

Legacy MEX infrastructure is provided for compatibility

matlab,compatibility,mex

The message Legacy MEX infrastructure is provided for compatibility; it will be removed in a future version of MATLAB. just means that the way of setting up MEX with mexopts.bat (Windows) and mexopts.sh (*NIX and MAC) is deprecated and an XML based configuration system ("infrastructure" in their words) will be...

Call MEX function without blocking main thread

multithreading,matlab,mex

Without editing the MEX file, one way is with batch: c = parcluster(); job = batch(c, @myMEXfun, numOutputs, {myinput1,myinput2}); % do something else in MATLAB job.wait(); out = job.fetchOutputs(); There are also possibilities with parfeval: p = gcp(); f = parfeval(@myMEXfun, numOutputs, myinput1, myinput2); % do something else in MATLAB...

error LNK 2019: unresolved external symbol (Matlab)

c,matlab,visual-studio-2012,mex,lnk2019

looks like that the problem is that you're only compiling only file1 which has calls to function from file2. So, you need them both in the compiling order. what about mex 'T:\Matlab\SRVF_FDA\DynamicProgrammingQ2.c' **SECOND FILE**? ...

Matlab Crahes upon fopen in Mex File

c,matlab,fopen,mex

Use w+ or r+ when using fopen, depending on what you want to do with the file and whethe you want to create it or simply open it. From (http://www.tutorialspoint.com/c_standard_library/c_function_fopen.htm) "r" Opens a file for reading. The file must exist. "w" Creates an empty file for writing. If a file...

Beginner's Mex Error - MatLab

matlab,fortran,mex

The error message you are seeing is from the Intel compiler. Your Fortran mex file is being treated as fixed-format Fortran irrespective of the fact that you are using a .f90 file extension (which traditionally signifies that the source is free format). You can easily recreate the error just with...

Cannot compile MEX LAPACK example

matlab,mex,lapack

After some more messing around, I figured out my (rather elementary) mistake. You need to specify the -lmwlapack option (and/or -lmwblas, as appropriate) to the linker: mex -largeArrayDims -lmwlapack matrixDivide.c It even says so on the MathWorks page I was trying to follow along on. RTFM!...

MxCalloc and MxFree with OpenMP results double free or corruption

c++,c,matlab,openmp,mex

The C MEX API is not thread-safe. According to the MathWorks Support Team: Since the MEX API is not thread safe, no MEX API functions can be used in the spawned threads... However, it seems that some MEX API functions have been made thread-safe, like mexErrMsgIdAndTxt. It seems that dynamic...

Debug a mex function in Visual Studio

c++,matlab,visual-studio,debugging,mex

Turns out <MATLABROOT>\bin\matlab.exe actually runs <MATLABROOT>\bin\w64\matlab.exe. So if I ask Visual Studio to run that, breakpoints are triggered as expected. Running MATLAB this way under the debugger is a lot slower than any other way, but at least now I can debug my code....

MKL library behaving differently in mex-files and in standalone C++

c++,matlab,linear-algebra,mex,lapack

I've tried to reproduce with an example on my end, but I'm not seeing any errors. In fact the result is identical to MATLAB's. mex_chol.cpp #include "mex.h" #include "lapack.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // verify arguments if (nrhs != 1 || nlhs >...

TBB acting strange in Matlab Mex file

multithreading,matlab,initialization,mex,tbb

According to the scheduler class description: This class allows to customize properties of the TBB task pool to some extent. For example it can limit concurrency level of parallel work initiated by the given thread. It also can be used to specify stack size of the TBB worker threads, though...

MATLAB .m file to .mex file using Matlab Compiler

c++,c,matlab,mex

MATLAB Compiler does not do what you want. MATLAB Compiler takes your .m code and encrypts and archives it into a .ctf (Component Technology File) file. It then produces a thin wrapper (either a .exe file, or a .dll library file along with files to enable calling the library from...

Combining matlab code and c/c++ code for mex function using Matlab Coder

c++,c,matlab,mex,matlab-coder

Firstly: you can call back into MATLAB from your generated C code or generated MEX file, using coder.extrinsic. If for some reason you have an existing MEX file without source code that you need to call, you can do this in the same way as for any other MATLAB command....

finding local mean in an image using mex-cuda

matlab,cuda,mex

Here's my 2 cents regarding local mean and local std. You should check whether using matlab's optimized built-in functions (conv2 and stdfilt , with their gpu support) gives you better performance than a "simple" mex version. For example, to take the local mean, the fastest will be to use conv2...

Error while compiling OpenTLD compile.m

c++,matlab,visual-studio,opencv,mex

I was able to solve the issue, it was some syntax issue as I was using a recent version of Matlab, 2013b. It's funny how all the forums online pointed me towards the 32-64 bit problem. Anyway I am posting the solution here so that in future it might help...

Is it possible to have a mexopts.bat that links both 32 AND 64bit compilers?

matlab,compiler-construction,mex

Thanks to Peter's comment, I investigated the command line options. An automatic way of doing what I need is: version = mexext; if (version(5) == '3') % this is 32bit % include 32bit version code elseif (version(5) == '6') % this is 64bit % include 64bit version code else %...

Why doesn't matlab find this function call?

python,matlab,mex

computer('arch') returns glnxa64 which stands for GnuLiNuX 64bit. You have downloaded binaries for Win32bit (mexw32), Win64bit (mexw64) and IOS on Intel (mexmaci64). Either get the source files to compile it yourself or the binaries for linux.

mxGPUGetDimensions returns an array with zeroes in between the dimension sizes

c,matlab,cuda,mex

I have to preface this by saying that I have never worked with the Matlab mex interface before, however.... What is clearly happening is that there is a mismatch in size between what mxGPUGetDimensions is returning, and what you code is using for mwSize. The result you get [5, 0,...

mex file compiled without errors but not working in matlab

matlab,visual-studio,64bit,mex

Pre-compiled header shenanigans A problem with the Visual Studio version of the code is the pre-compiled header file stdafx.h causing the compiler to ignore any code above it (the mex.h include): #include "mex.h" #include "stdafx.h" // ANYTHING above here is IGNORED! #include "matrix.h" Move the stdafx.h include to the top...

Passing a big matrix from Matlab to C using mex: Matlab crashes

c++,c,matlab,matrix,mex

As you pointed yourself in your question, your code is only suited to read full matrices as a second argument. When prhs[1] is a sparse matrix you can no longer access it as a full matrix using *(y+count): it is SPARSE, it does not occupy n entires in memory, but...

how to understand the linkagemex function inside of the defaule linkage function in matlab

matlab,mex

As @m.s. mentions, you've found a call to a MEX function. MEX functions are implemented as C code that is compiled into a function callable by MATLAB. As you've found, you can't step into this method (as it is compiled C code, not MATLAB code), and you don't have access...

How do use FFTW lib file in MATLAB MEX-file?

c,matlab,mex,fftw

You need to match a 64-bit FFTW library with 64-bit MATLAB (you are building a .mexw64 file). Your build command mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c Should point to a folder with the 64-bit FFTW libraries. For example: mex -LC:\fftw-3.3.4-dll64 -llibfftw3-3.lib test.c...

How do I call a c function from inside a mex file in Matlab?

matlab,mex

The documentation for mex has two subsections that describe how to build a MATLAB extension when the source code is spread over multiple source files. Mostly, all you need to do is: mex mexname.c helper1.c helper2.o The result is automatically named according to the first file passed in. For more...

Way to send OpenCV Mat to MATLAB workspace without copying the data?

c++,matlab,opencv,mex

Usually I do the input and output just like that, attaching a pointer to deal with the input and looping over elements on output. But, I think the output can be done in a similar manner to the input, although not without a copy of some sort. The only way...

OpenMP Matrix-Vector Multiplication Executes on Only One Thread

c++,multithreading,parallel-processing,openmp,mex

Did you include this snippet in #pragma omp parallel{...} or you might be missing the word parallel?

How to determine input sequence in c-mex s-function?

matlab,simulink,mex,s-function

Problem solved now, see edited first post.

Invalid mex-file, libarmadillo, cannot open shared object file

matlab,shared-libraries,mex,armadillo

So I found out how to run it. Now it's segfaulting :/ And I'm fairly confident it's not the code itself, because I can compile and run the exact same code outside Matlab. I'll try to find out what's wrong, and if it's relevant, I'll post my adventures here later...

Fortran in MatLab - Error in mex Setup

matlab,mex

You have to install Windows SDK 7.1 or one of the other compilers listed in the documentation. Notice the differences between 32 bit and 64 bit.

Locating and/or calling a built-in MATLAB MEX file

matlab,mex

The function imhistc, as the error implies, is a precompiled mex file, so you won't have direct access to its source code. The reason which imhistc doesn't work is that imhistc is in a directory named private located in the same folder with imhist. You'll note that if you look...

compiler for Matlab function block R2011b

matlab,compiler-construction,mex

By examining your comments, first we have asked you to choose the yes option to see whether or not your computer has any valid compilers installed. You have chosen that and it cannot locate any valid compilers. As such, you don't have any compilers installed on your computer. Usually if...

compile .C file Include library using mex - error LNK2019: unresolved external symbol - for NPTrackingTools

c,matlab,visual-c++,3d,mex

The library (.lib) you are trying to link to seems to be a C++ library, although these functions have C entry points (check with Dependency Walker). I got it to compile by renaming your mexFunction source from .c to .cpp, putting the header and source in the same folder, and...

How can I use C generated code from Simulink into a MATLAB script

c,matlab,simulink,mex

Not sure about the C code approach, but you could generate an executable using the RSIM target. This is relatively easy to implement and should speed up the execution. See Deployment of Simulink Models and Using RSim Target for Batch Simulations for more details.

Passing mxArray to mexCallMatlab fails

matlab,mex

Reusing data buffers Reusing the data pointer from mxArray *mask for mxArray *maskTransposed is asking for trouble, as MATLAB has rigorous mechanisms for reference counting as shared-data arrays are an important part of MATLAB's memory optimizations. Instead, duplicate the whole thing with mxDuplicateArray: mxArray *maskTranspose = mxDuplicateArray(mask); There is an...

QT exec() command crash

c++,matlab,qt,qt4,mex

dialog.exec() spins a local event loop that doesn't integrate well with the one that Matlab itself is spinning. Thus the crash. Conversely, you're banking on Matlab doing the right thing as far as its own event loop being compatible with Qt's requirements goes. This doesn't hold on all platforms, unfortunately,...

Creating and Passing of mxArray Data from other functions to Mex gateway function

c,matlab,mex

Ok, I should never again ask a question without a minimal example. The simple problem was, that I forgot to return the *mxArray... Both possibilities to pass the mxArray work as they should: A) Return mxArray* mxArray* createFoo() { mxArray* myArray; myArray = mxCreateDoubleMatrix(1,1,mxREAL); *mxGetPr(myArray) = 3; mexPrintf("*mxGetPr(myArray)= %f\n", *mxGetPr(myArray));...

mex error 206 Matlab

c++,matlab,mex

I figured it out. My mexopts.sh file was pointing to an old version of mac so I had to manually edit that file and change 10.7 to 10.9.

How to get function calling function from a MEX file

matlab,mex

Calling "dbstack" using "mexCallMATLAB" from within the MEX function should do the trick. Just need to be a little careful when converting the output of "dbstack", which is a MATLAB struct, into a string. This is the C MEX code #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const...

free() and mxFree() in MATLAB - freeing memory twice

matlab,memory-management,free,mex

The second loop does not index correctly for tau. You are defining indexing for tau as #define tau(a, b) tau[b+a*NrSensor] Let us walk through the second loop assuming NrSensor = 10 and len_zr = 5. For this case max value of loop variable i is 9 and max value of...

How to use 'mex' in Matlab

matlab,mex

In order to compile a mex function using the mex command, you first need to ensure the following: You have a c/c++ compiler installed You have told Matlab about it using the mex -setup command. In more detail: 1.You have a c/c++ compiler installed: Matlab provides a 32-bit compiler which...

Error when compiling/mexing imrender function with OS X in Matlab

c++,osx,matlab,mex

I can't verify this as a solution for you because it compiles fine on my machine with VS2012, but my suggestion would be to move the instantiations below the declarations and definitions of the specializations. Edit instances.inc and move the following lines: // Instantiations template class QPBO<int32_t>; template class QPBO<int64_t>;...

Invalid MEX-file when compiling with openMP and gcc

c,matlab,gcc,openmp,mex

I copied the LIBGOMP_64-1.DLL from the mingw/bin directory to the directory where the mex file is and now it works...

Can I detect MATLAB termination other than by way of a mex file mexAtExit handler?

matlab,mex

Does it work to mexLock() your MEX file so that it doesn't get unloaded, so the delete methods can do the right thing at shutdown?

How can I use the kd-tree file exchange and mex in matlab?

c++,c,matlab,mex,kdtree

To mex all source files, you have to call the mex function. To call mex for all cc-files in a directory, use for file = dir('*.cc'); mex(file.name) ; end ...

Access string property of object stored in mxArray

c,matlab,mex

You need to allocate str before you call mxGetString (although it may be easier to use mxArrayToString instead, see bottom). testMEXException.cpp #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mxArray *except, *char_ident; mwSize strlen; char *str; // catch exception except = mexEvalStringWithTrap("unknownfunction"); // get identifier...

Beginner grappling with octave and mex issues

c++,namespaces,octave,mex

I can't even compile (link, actually) in VS2013 unless I define void testMethod() in namespace test. This works: //test.cpp #include "test.h" #include <iostream> using namespace std; namespace test { void testMethod() { cout << "this works." << endl; } } Without namespace test{ ... }, there are unresolved symbols: myhello.obj...

Compiling MEX file from C [closed]

c,matlab,mex

in line 11,12 you have defined x,yas the output and input of the function 11: #define y plhs[0] 12: #define x prhs[0] but in line 15,16 you have defined x,yas variables of type double 15: double y, x, p; 16: int Y, X; you should change the name of the...

MATLAB crashes when it reaches mxSetPr in a mex file

matlab,mex

The memory passed to mxSetPr must be allocated with mxMalloc or mxCalloc, NOT with malloc, new, etc. From the mxSetPr docs page: void mxSetPr(mxArray *pm, double *pr); ... pr Pointer to the first element of an array. Each element in the array contains the real component of a value. The...

How to configure mex for MATLAB 2011 with MinGW

c,matlab,gcc,mex

Despite having "w64" in the file name, i686-w64-mingw32-gcc.exe generates 32-bit binaries. To generate 64-bit binaries, use x86_64-w64-mingw32-gcc.exe. In the cygwin package installer, look for mingw64-x86_64-. "mingw64" GCC toolchains in the list below. The first targets 32-bit systems and the second 64-bit. They are named this way because they are from...

Multithreaded (pthreads) MATLAB mex function causes MATLAB to crash after exiting

c,multithreading,matlab,pthreads,mex

The MEX API (includes the mx* functions) is NOT thread safe (MathWorks Support Team). You can only call mx*/mex* functions from the main MATLAB thread, with a few exceptions (see bottom). In doThread, which is launched with pthread_create, you are calling several functions that can't be used there: mxCreateCellMatrix mxCreateDoubleMatrix...

Call C/C++ code from Python

python,c,matlab,mex

If you can build your program as a shared library, then you can use the ctypes foreign-function interface to call your functions. This is often less work (and less complex) than wrapping the functions with Cython or writing your own C-API extension, but it is also more limited in what...

How to increase the speed of code written in Matlab

performance,matlab,mex

The short answer: compiling matlab code is not going to get you a much speed up, if any. The longer answer: The Matlab Compiler is more for letting you deploy matlab code for use on machines which don't have matlab, rather than for getting a speed up. In fact, from...

How to dynamically create an array of mxArray in a MATLAB mex file

matlab,mex

I think you just want an array of mxArray*s, which is straightforward with new or malloc. You can't have an array of mxArrays, only pointers to them. The mxArray comes from typedef struct mxArray_tag mxArray;, where mxArray_tag is not defined, hidden in the MathWorks implementation. Thus, you can't even do...

Huge fort.# files when running gfortran

osx,matlab,fortran,mex,gfortran

In Fortran, contrary to most other languages, one can write to a unit (~=file object, or file descriptor in some other languages) without first opening it (connecting the unit to a file). In that case, gfortran will implicitly create a file in the current working directory called 'fort.N', where N...

MATLAB mex routine does not return correct value

c++,matlab,mex

plhs[0] = mxCreateDoubleMatrix(1,ncols,mxREAL); On the line above the mxCreateDoubleMatrix call has already allocated a matrix of size 1 x ncols for you. outMatrix = MyarrayProduct(inMatrixA,inMatrixB,ncols); All you're doing here is over-writing the value of outMatrix, i.e. the memory location where it points. You're not actually overwriting the memory that mxCreateDoubleMatrix...

Retrieve error message string in C in MEX file

matlab,mex

One solution I found is to call getReport using mexCallMATLAB, and pass the exception object to it. It will return an mxArray of Char type containing the message. Example with using mexCallMATLABWithTrap to call evalc: // cmd is an mxArray * of Char type; it's the input to evalc mxArray...

Mex files and memory management

matlab,memory,mex

That is correct, the data buffer for the original A is destroyed by MATLAB and a new buffer is created (the same mxArray structure address is reused presumably by copying the new one onto the original after deallocating the original array's data buffer). This is assuming you are not writing...

Using OpenCV with Matlab: mex does not find header files

matlab,opencv,mex

"Without the make install" is the problem. The include files and built libraries are scattered all over the source tree, as determined by the build system. make install collects all the headers that are appropriate for use by users of the library and puts them in one directory for including....

Mex File dot product

c,matlab,mex

That's because you're not returning the result of the dot product. z makes a local copy of itself in your dotProd function. Even though you are making modifications to z, those changes are not reflected because the scope of z inside dotProd is of local scope. You need to update...

MATLAB Compiler

matlab,mex,matlab-compiler

You can use MinGW, but it is not straightforward. See this Q&A. The accepted answer suggest to compile and link MEX files outside of MATLAB, which is fine, but it's simple to just create mexopts.bat to do this. A good mexopts.bat for MING is hosted here. Pick a MINGW distribution...

MEX fortran file using Gnumex and MinGW (g77)

matlab,fortran,mex,fortran77

emphasized textFinally, I was able to pin point the issue and I thought it might be beneficial to others who may be facing the same issue (or similar to this one) to share the answer. Let me just mention that it was looking strange to me at the first place...

How to print C-preprocessor variables like __LINE__ with mexErrMsgTxt() In Matlab MEX

c++,c,debugging,mex,c-preprocessor

Concatenating preprocessor tokens works as long as you only use __FILE__, __LINE__ and a string literal as message. Then you can write something like #define STRINGIZE_I(x) #x #define STRINGIZE(x) STRINGIZE_I(x) #define myassert(isOK, astr) ( (isOK) ? (void)0 : (void) mexErrMsgTxt(__FILE__ ":" STRINGIZE(__LINE__) ": " astr) ) Unfortunately, __PRETTY_FUNCTION__ is not...

Matlab 2014b and mex files, has anyone been able to use Visual Studio Express?

matlab,visual-studio,windows-7-x64,mex

Yes. I used to use that exact combination if I recall. Make sure you get the right version of it though. Share the actual problem and maybe we can work around it.

Error with mex file … …Index exceeds matrix dimensions. Index value 3 exceeds valid range [1-2] of array gesgroup

matlab,mex,matlab-coder

The issue is in initialisation gesgroup is initialised with size 1x2 but the line gesgroup = [group, horgroup]; will make it 1x4 ( as both group and horgroup are 1x2), you need to initialise it as such or as variable size e.g. gesgroup = zeros(1,4); or coder.varsize('gesgroup') I think the...