Answered
inv(matrix) takes shorter time than \ operator
1) Your example is so small as to make the timing irrelevant 2) You burden the \ method with creating another variable, B ...

13 years ago | 5

Answered
Pre-allocating Arrays and Optimizing memory
Some clarification on the use of cell arrays and []: A cell array is an array of variable pointers. That is, the "data" of a ...

13 years ago | 2

Answered
element in 2D array
Not exactly sure what you want, but here is code to find the minimum value: x = rand(2,2); m = min(x(:));

13 years ago | 1

Answered
Trimming the Size of a Array of Structures in a MEX file
It is possible to do the equivalent of structOut(cnt+1:end) = [] in a mex routine (see below), but first I would ask if it is re...

13 years ago | 2

| accepted

Answered
Is mat.h thread-safe?
The restriction about not "interacting with MATLAB", as you put it, has to do mainly with the MATLAB memory manager, which is no...

13 years ago | 2

| accepted

Answered
Sparse matrices: find indices of non-zero elements in C code
Here is a simple mex routine that mimics the display functionality for sparse matrices (prints only the non-zero values). You sh...

13 years ago | 1

| accepted

Answered
Can I get faster MatrixMultiplication using CUDA than with Matlab internal GPU implementation??
I'm curious how the times compare to this: C = mtimesx(A,B); MTIMESX can be found here: < http://www.mathworks.com/m...

13 years ago | 1

Answered
Ideas on why this DLL can be used exactly like a MATLAB function?
It is possible that CgCall is itself a mex routine (has a mexFunction interface etc). What version of MATLAB are you running?

13 years ago | 1

| accepted

Answered
How to convert 4 hex bytes into a single integer
Depending on the machine you are on, you may need to use the swapbytes function as well. E.g., try: swapbytes(typecast(uint...

13 years ago | 0

| accepted

Answered
Overload mtimes for double*char
The short answer is DON'T DO THIS! There are many built-in MATLAB functions that do (double)*(char) operations and depend on get...

13 years ago | 0

| accepted

Answered
How to save a c++ readable Mat file
Are you trying to read the compressed mat file into C++ without the aid of the MATLAB API library? If so, this is not at all tri...

13 years ago | 1

Answered
i cant understand meaning of this comment . whenever i run program it show this msg. suggest any solution
You have a function that directly or indirectly calls itself. It did so 500 times without returning in your run. That usually me...

13 years ago | 0

| accepted

Answered
MATLAB Engine: how to call functions?
Maybe you can adapt this FEX submission, which mimics the capability of mexCallMATLAB with an Engine interface: <http://www.m...

13 years ago | 2

Answered
Matrix multiplication result - where does it go?
Interesting question. The answer will probably depend on MATLAB version and JIT settings. TMW likely keeps stuffing more & more ...

13 years ago | 2

| accepted

Answered
Is there a maximum input size for mex? Segmentation Fault with large inputs
There is a bug in the mxArrayToString API function. It only copies the characters up to the first null character. It does not al...

13 years ago | 2

| accepted

Answered
Data type errors in tmwtypes.h while compiling with mex
I suspect the defines -DmwIndex=int -DmwSize=int -DmwSignedIndex=int were intended for older versions of MATLAB (R2006a and earl...

13 years ago | 2

| accepted

Answered
Is there a maximum input size for mex? Segmentation Fault with large inputs
What is the connection between len and the size of prhs[1]? How do we know this isn't simply a user input error? I would suggest...

13 years ago | 0

Answered
How to avoid the compiler error in _kids--Bad rule number 0
The lcc compiler that ships with MATLAB has bugs in it for the unsigned long long type. Your options are: 1) Change to a diff...

13 years ago | 1

| accepted

Answered
Random integer number generation
doc randperm

13 years ago | 1

| accepted

Answered
Mex compilation with header files
Have you tried the function form of mex yet? I.e., something like mex('-I','...whatever...','simulation.cpp') Also, wha...

13 years ago | 0

Answered
Mex compilation with header files
If your current directly is the directory that contains simulation.cpp and its associated header files, doesn't simply "mex simu...

13 years ago | 0

Answered
how to apply relational operators on matrix elements?
i(i>4) = 4; i(i<-4) = -4; or i = min(max(i,-4),4); But in the future avoid i as a variable name since that is wh...

13 years ago | 0

| accepted

Answered
Using Mex with Classes
One option is to keep your pointer in a high level variable (i.e., global) and set up a mexAtExit function to clean things up wh...

13 years ago | 0

| accepted

Answered
Faster way to initilize arrays via empty matrix multiplication?
Another (perhaps related) observation is that MATLAB does some pre 0 filling in the background in mex routines. E.g., I have run...

13 years ago | 3

Answered
C++ Mex compilation error. SharedMemory.cpp
It looks like you are missing the definition of the struct mxArray_tag. This used to be part of the matrix.h file up to R2010a, ...

13 years ago | 2

| accepted

Answered
Boost mex compilation error > SharedMatrix
The supplied lcc compiler is a C compiler only, not a C++ compiler. You will not be able to compile cpp files with lcc. You need...

13 years ago | 3

| accepted

Answered
MATLAB gives error while generating MEX file from the Fortran source code
You are missing the source code for the TEINIT routine, so there is no object routine TEINIT to link to at link time. I.e., some...

13 years ago | 0

| accepted

Answered
while true vs. for i= 1:Inf
In addition to what Per Isakson has written, I would add that the loop variable, after a certain point, will lose precision and ...

13 years ago | 1

Answered
How to use lapack in matlb to solve large eigenvalue problem
If you are well versed in the LAPACK functions and just need an interface, you can use this package from the FEX by Tim Toolan: ...

13 years ago | 1

Answered
Substituting NaN values of one matrix to another?
a = first matrix with NaN values b(isnan(a)) = nan;

13 years ago | 1

| accepted

Load more