mexFunction input arguments - integer (used in mxCreateDoubleMatrix)

Hi,
i want to use, integer mexFunktion input arguments to scale a a matrix:
% code
row = 1
call mxCopyPtrToInteger4(il_pr,il,row)
call mxCopyPtrToInteger4(iq_pr,iq,row)
ilq = (il-1)*(iq-1)
plhs(1) = mxCreateDoubleMatrix(ilq,1,0)
scoop dec.
mwPointer iq_pr, il_pr
mwSize ilq, row
integer*4 il, iq
il_pr and iq_pr are related to prhs(3) and prhs(4)
Output is allways a 1x1 Matrix.
But everything works fine when ilq is set manually to e.g. 50. Then the Matrix is 50x1.
I got the same problem if i use il instead of ilq in the mxCreateDoubleMatrix()
I would be glad if someone has some ideas.
kind regards
Alex
I use Matlab R2012b (Mac 64bit) and gcc gfortran 4.6

6 Kommentare

"Output is allways a 1x1 Matrix.": is this wanted or not wanted? What exactly is the question? How do you set "ilg manually to 50"? What is the contents of ilq, when you assign the value "not manaully"?
Thanks so far. Sry not to be clear. It should be a matrix Nx1 with N>1....rather a vector. So the Output is not correct. With manual i ment:
ilq = 50
ilq should be as mentioned above (il-1)*(iq-1)*. Just a int number. But however it seems that the mxCreateDoubleMatrix() command does not accept the input of ilq.
I hope this helps. Otherwise i have to switch to our native language ;)
Grüße Alex
Jan
Jan am 12 Nov. 2012
Bearbeitet: Jan am 12 Nov. 2012
On 64 bit machines, mxCreateDoubleMatrix expects 64 bit integers for the dimensions.
Is it your intentation that iq is overwritten in the 2nd line, while il is undefined?
call mxCopyPtrToInteger4(il_pr,iq,row)
call mxCopyPtrToInteger4(iq_pr,iq,row)
1. and how can i transfer the correct integer ....itried various functions. don't know why but it does not accept any input. Beside of my problem, there is no example in the matlab docu which shows the use of input arguments as matrix dimensions. Every example uses the m = mxGetM(prhs(1)) command which does not help in my case for various reasons.
mxGetM delivers a mSize datatype which is integer. mxCreateDoubleMatrix() needs mSize or Integer. I although tried to convert REAL*8 with the int() command no success either. every real input works.
2. sry, there is no overwriting in my code..typo ...i corrected it
Alexander
Alexander am 12 Nov. 2012
Bearbeitet: Alexander am 12 Nov. 2012
Hi Jan,
Thanks for the int64 hint etc. I have found this :
if i declear the input (matlab side) as int32 it works fine
eg.
a = int32(24)
c = mexfunction(a)
thanks again :D
I would say this is a poor way to go about things. Requiring the input to be int32 puts unnecessary restrictions on your mex code and it will not be robust. I would advise looking into using mxGetScalar instead.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Produkte

Gefragt:

am 12 Nov. 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by