Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: MEX function not returning calling sparse elements as expected
Replies: 13   Last Post: Oct 20, 2013 4:38 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
sharoze ali

Posts: 21
Registered: 10/7/13
MEX function not returning calling sparse elements as expected
Posted: Oct 12, 2013 4:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi All,

I have written a .m file which is creating function and calling MEX Function .In Mex I cant able access the Calling Sparse elements .Elements position is changed and not returning as expected.

calling function .m
===========
A = sparse(2,4);
A(1,1:4)=[0,0,8,0];
A(2,1:4)=[2,2,0,9];

Mex Function
==========
const mxArray *A = prhs[0];
mwSize M = mxGetM(A);
mwSize N = mxGetN(A);

double *pr = mxGetPr(A);
mwIndex *ir = mxGetIr(A);
mwIndex *jc = mxGetJc(A);

for(int x=0;x<M;x++)
{
for(int y=0;y<N;y++)
{
printf(" %d %d %8.4f ",x,y,pr[x + M*y]);
}
printf("\n");
}


Ans :-
0 0 2.0000 0 1 8.0000 0 2 0.0000 0 3 0.0000
1 0 2.0000 1 1 9.0000 1 2 0.0000 1 3 -1.#QNB

But Expected Ans:-
0 0 8 0
2 2 0 9



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.