row/column indexing in MEX file
Show older comments
Hi,
I am trying to figure out if it is possible to use row/column indexing in C code mex file. For example, I want to pass a 2D array (let's say A) from Matlab command window to a mex file and manipulate it as A[i][j] += 3 inside the mex . I haven't done C programming before and am unable to find an example code in Matlab documentation that does this. Currently I am indexing it as A[i+j*n_rows] which is quite inefficient. If this is possible how do I set it up in the mex?
Thanks, Kapil
Answers (1)
James Tursa
on 6 Sep 2011
0 votes
I don't think you are going to be able to write code that is significantly faster than A[i+j*n_rows]. You could allocate an array of column pointers and then use that to get [j][i] syntax to work, but I doubt it will be much faster.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!