![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 5
| Thank You |
| LennoZebra is offline | |
| | #2 | |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Quote:
Not sure what you mean by the above? | |
| itCbitC is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 5
| I used a FOR loop to cast each variable in the array up to a data type double. But when I try and set the array to the pointer like: *vrp = hab2; where hab2 is a array of 300 units, it tells me that they are incompatible data types? Thank You |
| LennoZebra is offline | |
| | #4 |
| Registered User Join Date: Sep 2008 Location: Toronto, Canada
Posts: 507
| No. Since every array element uses 4 byes for float vs. 8 bytes for double, you can not cast the entire array at once. |
| nonoob is offline | |
| | #5 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Do you want a copy of the values in a separate array, or do you want both arrays to point to the same place? If the later, there is no point, since a double and a float are stored differently. You should post that code that you tried.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #6 | |
| I like turtles Join Date: Sep 2009 Location: Ohio
Posts: 179
| Quote:
For example, a[2] is the same as *(a+2) anyway... Code: float a[4];
double b[4];
int i;
for (i = 0; i < 4; i++)
b[i] = (double)a[i];
| |
| Epy is offline | |
| | #7 |
| Registered User Join Date: Oct 2009
Posts: 5
| Here is the code that I am having problems with. Notice Code: #include "config.h"
#include "mex.h"
#include "f77-fcn.h"
extern void F77_FUNC (contrl, CONTRL)
(float *phi, float *delta);
void
mexFunction (int nlhs, mxArray* plhs[], int nrhs,
const mxArray* prhs[])
{
mwIndex i;
mwSize n;
double *vri, *vro;
double hab1, hab2[2];
float heg1, heg2[2];
float guo[300];
int k;
if (nrhs != 1 || ! mxIsNumeric (prhs[0]))
mexErrMsgTxt ("expects matrix");
n = mxGetNumberOfElements (prhs[0]);
plhs[0] = (mxArray *) mxCreateNumericArray
(mxGetNumberOfDimensions (prhs[0]),
mxGetDimensions (prhs[0]), mxGetClassID (prhs[0]),
mxIsComplex (prhs[0]));
vri = mxGetPr (prhs[0]);
vro = mxGetPr (plhs[0]);
if (mxIsComplex (prhs[0]))
{
double *vii, *vio;
vii = mxGetPi (prhs[0]);
vio = mxGetPi (plhs[0]);
for (i = 0; i < n; i++)
{
vro [i] = vri [i] * vri [i] - vii [i] * vii [i];
vio [i] = 2 * vri [i] * vii [i];
}
}
else
{
hab1 = *vri;
heg1 = (float)hab1;
F77_FUNC (contrl, CONTRL) (&heg1,(float *)guo);
heg2 [1] = guo[13];
heg2 [2] = guo[20];
//***** Important Part*********
for (k = 0; k < 3; k++)
vro[k] = (double)heg2[k]; //This Line is Having PROBLEMS
//I create the mex file using Octave and this part does not work
}
}
C still has to abide by all the normal rules inside this wrapper. But using the code above or: Code: //***** Important Part*********
for (k = 0; k < 3; k++)
hab2[k] = (double)heg2[k];
*vro = hab2; //This Line is Having PROBLEMS
*****I am able to cast the array properly, but I am having problems assigning the array to the value of the pointer***** Thank you for your help |
| LennoZebra is offline | |
| | #8 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| What kinds of problems are you having? Specifically. |
| tabstop is offline | |
| | #9 |
| Registered User Join Date: Oct 2009
Posts: 5
| if I use : Code: //***** Important Part*********
for (k = 0; k < 3; k++)
vro[k] = (double)heg2[k]; //This Line is Having PROBLEMS
//I create the mex file using Octave and this part does not work
If I use : Code: //***** Important Part*********
for (k = 0; k < 3; k++)
hab2[k] = (double)heg2[k];
*vro = hab2; //This Line is Having PROBLEMS
The wrapper can send out a single value very well, but I need a array to come out of the wrapper. Thank You |
| LennoZebra is offline | |
| | #10 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| So having looked up all these mxfunctions, if you want an array of doubles, shouldn't you create an array of doubles with your plhs[0] thing? It looks like you are not. |
| tabstop is offline | |
| | #11 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| *vro = hab2; //This Line is Having PROBLEMS That line should be: Code: vro = hab2;
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #12 |
| Registered User Join Date: Oct 2009
Posts: 5
| Awesome! Thanks Guys. No crashing anymore and the function is now outputting a array of zeros. I'm happier :-). I think there may be another problem with how I am declaring the mxCreateDoubleMatrix, but thats not a C issue. Thank You so Much for all your help! Hope everyone have a nice weekend |
| LennoZebra is offline | |
![]() |
| Tags |
| array, pointers |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| parent in a binary search tree | roaan | C Programming | 4 | 08-26-2009 07:08 PM |
| Problem in compiling targa2.c: error: field `ip' has incomplete type.. | Moony | C Programming | 0 | 03-20-2008 07:59 AM |
| failure to import external C libraries in C++ project | nocturna_gr | C++ Programming | 3 | 12-02-2007 03:49 PM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| change array data type | panfilero | C Programming | 2 | 10-16-2005 04:52 AM |