Prev: how can i get minimum positive value in an expression number of solutions, give me the code for this
Next: OFDM transmission into multipath channel
From: Oleg Komarov on 3 Feb 2010 13:34 "Etienne" I accidentally flagged as spam your post. It was not my intention. Oleg
From: Etienne on 4 Feb 2010 05:33 Hi James I have run the example code you sent, and the value of the field does not seem to change. NDIM is set to 0, even though I am sending in a value of 1. The value coming back out is then 1 again. I thought that there should maybe be a line CALL mxSetPr(ptrNDIM,ptrNDIMOBpr) but this does not seem to make a difference. I checked the object as well and it is a simple one classdef auto %UNTITLED3 Summary of this class goes here % Detailed explanation goes here properties Ndim=1 end methods end end I send this object into the mex file. I will try some other things. Thanks for the help. Etienne
From: James Tursa on 4 Feb 2010 16:13 "Etienne" <etienne.coetzee(a)airbus.com> wrote in message <hke7p1$oei$1(a)fred.mathworks.com>... > Hi James > > I have run the example code you sent, and the value of the field does not seem to change. NDIM is set to 0, even though I am sending in a value of 1. The value coming back out is then 1 again. I thought that there should maybe be a line > > CALL mxSetPr(ptrNDIM,ptrNDIMOBpr) > > but this does not seem to make a difference. I checked the object as well and it is a simple one > > classdef auto > %UNTITLED3 Summary of this class goes here > % Detailed explanation goes here > > properties > Ndim=1 The code you had originally listed assumed that Ndim was an int32 class variable. That is what I patterned my code after. But your Ndim above is *not* an int32 class variable, it is a double class variable. So it is clearly wrong to use mxCopyPtrToInteger4 and mxCopyInteger4ToPtr in this case. You need to use the Real8 routines instead, since Real*8 is equivalent to a MATLAB double type. e.g., #include <fintrf.h> C SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS) C IMPLICIT NONE MWPOINTER PLHS(*), PRHS(*) INTEGER NLHS, NRHS C C----------------------------------------------------- Real*8 NDIM, MATNDIM mwPointer mxGetProperty, mxGetPr, mxDuplicateArray mwPointer ptrNDIM, ptrNDIMpr mwIndex :: i = 1 mwSize :: n = 1 C PLHS(1)=mxDuplicateArray(PRHS(1)) ! PLHS(1) is an object mxArray ptrNDIM=mxGetProperty(PLHS(1),i,'Ndim') ! ptrNDIM is an int32 mxArray ptrNDIMpr=mxGetPr(ptrNDIM) ! ptrNDIMpr points to the int32 data C CALL mxCopyPtrToReal8(ptrNDIMpr,NDIM,n) ! extract the real*8 value MATNDIM=2*NDIM ! double it CALL mxCopyReal8ToPtr(MATNDIM,ptrNDIMpr,n) ! replace the real*8 value CALL mxSetProperty(PLHS(1),i,'Ndim',ptrNDIM) ! set the new property CALL mxDestroyArray(ptrNDIM) ! destroy our temporary mxArray for NDIM C----------------------------------------------------- C RETURN END And again, I would state that it would be wise to include checks for correct type, size, etc. in the variables before using them. If such checks had been present in the code it would have caught the type mismatch error that you have. e.g. check that PRHS(1) is the correct object type before duplicating it, check that the property Ndim is actually present, check that Ndim is a non-empty double, etc. etc. James Tursa
From: James Tursa on 4 Feb 2010 16:43 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hkfd91$rnd$1(a)fred.mathworks.com>... > > ptrNDIM=mxGetProperty(PLHS(1),i,'Ndim') ! ptrNDIM is an int32 mxArray > ptrNDIMpr=mxGetPr(ptrNDIM) ! ptrNDIMpr points to the int32 data Cut and paste typo ... those are double class, not int32 class. James Tursa
From: Etienne on 4 Feb 2010 18:35
Thanks James I will try it tomorrow. We are half a day ahead of you folks. I assume you are in the USA. Regards Etienne |