|
Hi,
I created a new S-function from scratch copy of sfun_basic.c file & included my code in. I need to call some functions that are defined in a DLL file. How to include the dll in my code?
Thanks
|
|
|
|
|
Hi,
Basically you must include the DLL header file to your code and also import its library (*.lib).
Best regards,
A. Riazi
|
|
|
|
|
Thanks for your reply, but how this can be reached? to import the dll files with the c -file created?
Thanks again
|
|
|
|
|
Hi,
I create a mex project a dll C++ project.
My project contains many files, but it's under one dll.
I will give you an example how I am using my dll.
(Suppose I want to call FFT,
mexProject('FFT') ; mexProject is name of the dll,FFT is the routine)
I am using a database that a created from a MAT file.
I created my database on matlab and with a program I managed to pass it to c++, as a result I have an header and cpp file.
Exapmle:
The cpp contains
############################################################
#include "type_def.h"
#include "phydb_m2h_rf_front_tx.h"
namespace M2HPhyRfFrontTx
{
char __MAT2H_RF_FRONT_TX_bw[3]={50, 53, 0};
SPYWORD __MAT2H_RF_FRONT_TX_Coeff[129]={0.000000F, 0.000000F, -0.000000F, -0.000000F, -0.000000F, 0.000000F, 0.000000F
, -0.000000F, -0.000000F, -0.000000F, 0.000000F, 0.000001F, 0.000000F, -0.000002F, -0.000003F, 0.000001F, 0.000008F
, 0.000007F, -0.000009F, -0.000022F, -0.000004F, 0.000037F, 0.000043F, -0.000025F, -0.000100F, -0.000048F, 0.000125F
, 0.000193F, -0.000031F, -0.000339F, -0.000249F, 0.000315F, 0.000657F, 0.000082F, -0.000919F, -0.000900F, 0.000597F
, 0.001808F, 0.000639F, -0.002052F, -0.002586F, 0.000764F, 0.004211F, 0.002352F, -0.003866F, -0.006296F, 0.000189F
, 0.008609F, 0.006592F, -0.006244F, -0.013714F, -0.002569F, 0.016193F, 0.016273F, -0.008734F, -0.028955F, -0.011380F
, 0.031037F, 0.041914F, -0.010655F, -0.075389F, -0.051658F, 0.101508F, 0.298287F, 0.388619F, 0.298287F, 0.101508F
, -0.051658F, -0.075389F, -0.010655F, 0.041914F, 0.031037F, -0.011380F, -0.028955F, -0.008734F, 0.016273F, 0.016193F
, -0.002569F, -0.013714F, -0.006244F, 0.006592F, 0.008609F, 0.000189F, -0.006296F, -0.003866F, 0.002352F, 0.004211F
, 0.000764F, -0.002586F, -0.002052F, 0.000639F, 0.001808F, 0.000597F, -0.000900F, -0.000919F, 0.000082F, 0.000657F
, 0.000315F, -0.000249F, -0.000339F, -0.000031F, 0.000193F, 0.000125F, -0.000048F, -0.000100F, -0.000025F, 0.000043F
, 0.000037F, -0.000004F, -0.000022F, -0.000009F, 0.000007F, 0.000008F, 0.000001F, -0.000003F, -0.000002F, 0.000000F
, 0.000001F, 0.000000F, -0.000000F, -0.000000F, -0.000000F, 0.000000F, 0.000000F, -0.000000F, -0.000000F, -0.000000F
, 0.000000F, 0.000000F};
char __MAT2H_RF_FRONT_TX_1_bw[3]={53, 48, 0};
SPYWORD __MAT2H_RF_FRONT_TX_1_Coeff[2]={1.000000F, 0.000000F};
char __MAT2H_RF_FRONT_TX_2_bw[4]={49, 48, 48,
0};
##########################################################
and the header files contains
#ifndef M2HPHYRFFRONTTX_H
#define M2HPHYRFFRONTTX_H
namespace M2HPhyRfFrontTx
{
typedef struct
{
char *bw;
UINT16 I;
UINT16 MemSpS;
UINT16 Len;
SPYWORD Delay;
SPYWORD *Coeff;
UINT16 MemLen;
} RF_Front_Tx_DB;
const int RF_FRONT_TXS_LEN=4;
extern RF_Front_Tx_DB RF_FRONT_TXS[4];
} // End Of Namespace M2HPhyRfFrontTx
#endif
#########################################################
I have several files like that, I pass several MAT files
to a C++ files.
I have recognized when I add a few files of database on C++
I am getting the following message :
Invalid MEX-file 'M:\...\mxProject.dll': 'M:\...\mxProject.dll' is not a valid Win32 application.
Please help me.
All the memory allocation are static in my database files.
Thanks,
Shai
All
|
|
|
|
|
a friend of mine has written this code where he generates a dll in vc++ complier 6.0 .he links successfully with all libs he needs to generate the dll.this dll had a mexFunction entry point, which somehow gives him an error when he tries to use this dll in matlab command prompt.the error message he gets is
Mex file entry point is missing. Please check the (case-sensitive)
spelling of mexFunction (for C MEX-files), or the (case-insensitive)
spelling of MEXFUNCTION (for FORTRAN MEX-files).
??? Invalid MEX-file 'C:\Program Files\OpenCV\samples\c\krishna\LK\Debug\LK.dll': The specified module could not be found.
.
his code where he generates the dll looks like this.he is successfully able to link and generate the dll using VC++ 6.0. he uses matlab R14.
could anyone help ir comment on this problem.
#include "mex.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "stdio.h"
void mexFunction(
int nlhs, // Number of left hand side (output) arguments
mxArray *plhs[], // Array of left hand side arguments
int nrhs, // Number of right hand side (input) arguments
const mxArray *prhs[] // Array of right hand side arguments
)
{
/* Check for proper number of arguments. */
if (nrhs != 1 && nrhs != 2 && nrhs != 3) {
mexErrMsgTxt("One, two, or three inputs required.");
} else if (nlhs > 2) {
mexErrMsgTxt("Too many output arguments");
}
double *image1,*image2,*velocity_x,*velocity_y,*velox, *veloy;
int imysize1,imxsize1,imysize2,imxsize2 ;
int dim[2],i,j,size[2];
int x,y;
unsigned char *im_1,*im_2;
im_1 = (unsigned char *)mxGetData(prhs[0]);
im_2 = (unsigned char *)mxGetData(prhs[1]);
// printf("the value is %c",im_1[2]);
/* Assign pointers to first input image*/
//image1 = mxGetPr(prhs[0]);
imysize1 = mxGetM(prhs[0]);
imxsize1 = mxGetN(prhs[0]);
printf("Input image 1: number of columns: %d, number of rows:%d \n",imxsize1,imysize1);
int no_rows1 = imysize1;
int no_col1 = imxsize1;
int width = no_col1;
int height = no_rows1;
/* Assign pointers to second input image*/
//image2 = mxGetPr(prhs[1]);
imysize2 = mxGetM(prhs[1]);
imxsize2 = mxGetN(prhs[1]);
printf("Input image 2: number of columns: %d, number of rows:%d \n",imxsize2,imysize2);
int no_rows2 = imysize2;
int no_col2 = imxsize2;
/* for(y=0;y<columns1;y++)
{
="" for(x="0;x<rows1;x++)
" image1_[y+x*columns1]="int" ((image1[y+x*columns1])*255);
="" image2_[y+x*columns1]="int" ((image2[y+x*columns1])*255);
="" printf("value="" at="" %d="" and="" is="" %f\n",x,y,((image1[y+x*columns1])));
="" }
="" }*=""
="" printf("size="" %d",sizeof(image1_));
="" printf("columns="" %d\n",columns1);
="" *="" first="" image="" converted="" to="" 8="" bit="" value*=""
="" cvmat="" *image_1="cvCreateMatHeader(no_rows1,no_col1,CV_8UC1);
" cvsetdata(image_1,im_1,(width*1));
="" second="" *image_2="cvCreateMatHeader(no_rows1,no_col1,CV_8UC1);
" cvsetdata(image_2,im_2,(width*1));
="" cvsize="" size="cvGetSize(image_2);
" printf("width="" height="" %d",size.width,="" size.height);="" gives="" correct="" value
="" printf("\n="" creation="" of="" headers="" done\n");
="" for(y="0;y<height;y++)
" unsigned="" char="" c="im_1[x+y*width];
" c1="im_2[x+y*width];
" image_1-="">data.ptr[x+y*width] = c;
image_2->data.ptr[x+y*width] = c1;
}
}*/
// printf("\n assignment done\n");
//printf("value at 0 and 0 is %f\n",CV_MAT_ELEM(*image_2,double,0,0));
/* works fine*/
//printf("the unchar pointer value at 0 and 0 is %d\n",(image_2->data.ptr[241]));
//printf("step is %d \n",image_2->step);
/*creation of velocity headers*/
CvMat* velx= cvCreateMatHeader(no_rows1,no_col1,CV_32FC1);
cvCreateData(velx);
CvMat* vely= cvCreateMatHeader(no_rows1,no_col1,CV_32FC1);
cvCreateData(vely);
/*creation of other required parameters*/
const bool use_previous = false;
const double LAMBDA = 100.0f;
CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER;
criteria.max_iter = 64;
criteria.epsilon = 0.01f;
// printf("\n All assignment done\n");
cvCalcOpticalFlowLK(image_1,image_2,cvSize(7,7),velx,vely);
//cvCalcOpticalFlowHS(image_1,image_2,use_previous,velx,vely,LAMBDA,criteria);
// printf("\n lucas kanade done");
dim[0] = imysize1;
dim[1] = imxsize1;
plhs[0] = mxCreateNumericArray(2,dim,mxDOUBLE_CLASS, mxREAL);
velocity_x = mxGetPr(plhs[0]);
plhs[1] = mxCreateNumericArray(2,dim,mxDOUBLE_CLASS, mxREAL);
velocity_y = mxGetPr(plhs[1]);
//printf("Velocity %f \n",CV_MAT_ELEM(*velx,float,5,5));
CvSize size_vel = cvGetSize(velx);
// printf("velocity size width %d height %d \n",size_vel.width,size_vel.height);
for(x=0;x<width;x++)
{
="" for(y="0;y<height;y++)
" velocity_x[x+y*width]="velx-">data.fl[x+y*width];
velocity_y[x+y*width] = vely->data.fl[x+y*width];
//velocity_x[y+x*columns1] = CV_MAT_ELEM(*velx,float,x,y);
//velocity_y[y+x*columns1] = CV_MAT_ELEM(*vely,float,x,y);
//printf("%f\n",velocity_x[y+x*columns1]);
}
}
}
|
|
|
|
|
Hi, I'm doing research in TDD(Test Driven Development) in embedded systems. That means writing tests first, and then coding. Right now I am writing some tests for algorithms in MATLAB, and if I want to use the same tests in embedded environment, exp: in C++, the only way is to use MEX file? And I think the translation can only be done manually, not automaticly. I don't know whether my understanding is correct. Thanks a lot.
|
|
|
|
|
For Mr.Riazi
I have tried to do the compute prime example. but i could not create the dll successfully. The following are the error messages i recd.
D:\myprojects\mexfunction\mexfunction.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/mexFunction.pch': No such file or directory
Error executing cl.exe.
Please let me know where i could be wrong. Actually i have used the source code given by you without any change and followed the steps as per your webpage information.
With regards
Sekar
|
|
|
|
|
i tried to build this prog which creates a structure and sends it over the comm port it gave me this error
pls tell me what could be wrong?
thank you
Ajo T.
--------------------------------------------------------------
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
comp3.obj
Creating library _lib8741.x and object _lib8741.exp
comp3.obj : error LNK2001: unresolved external symbol "void __cdecl writecom(struct mxArray_tag *)" (?writecom@@YAXPAUmxArray_tag@@@Z)
comp3.dll : fatal error LNK1120: 1 unresolved externals
D:\MATLAB7\BIN\WIN32\MEX.PL: Error: Link of 'comp3.dll' failed.
??? Error using ==> mex
Unable to complete successfully
-----------------------------------------------------------------
|
|
|
|
|
sir,
please help me with mex files structure application.
how can we send structures with no field values to mex files and then enter the values in c/c++ program and send it back into matlab?.are the way in which data stored in matlab and c/c++ different ?
thank you for your help
Ajo ,
|
|
|
|
|
There is no way to pass a structure to a mex function directly, but you can pass every elements as a seperate matrix to mex function. Here is an example:
[x,y]=myMexFunction(structure.element1, structure.element2, ...);
Best regards,
A. Riazi
|
|
|
|
|
Hi,
I would like to implement this routine written in C and to put it in a mex-file... Unfortunally, these matrices of 4 dimensions don't have the same increment... I have thought of that for several days and still have no idea...
<br />
void advection( double ****eam_elm,double *cl,int ng,double ****gam)<br />
{ <br />
int i,j,k, i1, j1, k1;<br />
for (i=0; i<6; i++)<br />
{<br />
i1 = cl[i];<br />
for (j=0; j<6; j++)<br />
{<br />
j1 = cl[j];<br />
for (k=0; k<6; k++)<br />
{<br />
k1 = cl[k];<br />
gam[j1][i1][k1][1] = gam[j1][i1][k1][1] + eam_elm[j][i][k][1];<br />
gam[j1][i1][k1][2] = gam[j1][i1][k1][2] + eam_elm[j][i][k][2];<br />
}<br />
}<br />
}<br />
}<br />
Thanks in advance for your help,
Rosette.
|
|
|
|
|
I need help in writing a code for program using mex files.
program involves one input array of size say 6(boolean array),and some operation on this array, and returns this modified array.
prabhu
|
|
|
|
|
Hi Mr. A. Riazi
I have try your example, and it work very well, but when I try to export Intel lib, doesn’t work I followed all the steps that you explain in your example.
Have look for my simple example :
#include "StdAfx.h"<br />
#include "dll_conv.h"<br />
<br />
#include "mex.h"<br />
<br />
#pragma comment(lib, "libmx.lib")<br />
#pragma comment(lib, "libmat.lib")<br />
#pragma comment(lib, "libmex.lib")<br />
#pragma comment(lib, "libmatlb.lib")<br />
<br />
#include "nspconv.h"<br />
#pragma comment(lib, "nsp.lib")<br />
<br />
<br />
<br />
<br />
void mexFunction( int nlhs, mxArray *plhs[],<br />
int nrhs, const mxArray *prhs[] )<br />
{<br />
double *x, *h, *y;<br />
int nx, nh,cols;<br />
<br />
<br />
nx = mxGetN(prhs[0]);<br />
nh = mxGetN(prhs[1]);<br />
<br />
<br />
<br />
x = mxGetPr(prhs[0]);<br />
<br />
h = mxGetPr(prhs[1]);<br />
<br />
<br />
<br />
cols = nx + nh - 1;<br />
plhs[0] = mxCreateDoubleMatrix(1, cols, mxREAL);<br />
y = mxGetPr(plhs[0]);<br />
<br />
nspdConv(x, nx, h, nh, y);<br />
<br />
return;<br />
}
This is the errors I have, very strange , I have include nspconv.h (it’s a Intel headers) and the compiler said that we have errors in nspconv.h:
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(31) : error C2061: syntax error : identifier 'nspdConv'
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(34) : error C2146: syntax error : missing ';' before identifier 'NSPAPI'
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(34) : fatal error C1004: unexpected end of file found
thanks
|
|
|
|
|
Hi,
I don't understand what you mean for export Intel lib. May be you mean importing Intel library.
Also please check the Intel Library manual for any preprocessor definition that is required for your project.
Best regards,
A. Riazi
|
|
|
|
|
yes sorry I mean importing Intel library.
ok I m going to check the Intel Library manual,and I well tel you what new
thanks
|
|
|
|
|
Hello
I work in Matlab environment and I want to use some Intel library,(because the Intel lib is already compile and optimize for Intel processor :-> ) can you explain my how to call function in Intel library from my mexfunction
Thanks
|
|
|
|
|
Hi,
It is very simple to do. Just include the header files of Intel library where you want to use its functions. Then add Intel library files (*.lib) to your project. You can use desired functions in your mex. Here is an example:
#include "some Intel header file.h"
#pragma comment(lib, "the Intel lib file.lib")
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
if (nrhs != 1)
{
mexErrMsgTxt("One input required.");
}
else if (nlhs > 1)
{
mexErrMsgTxt("Too many output arguments");
}
YourIntelFunction(some input);
}
Best regards,
A. Riazi
|
|
|
|
|
Ok thanks
I’ll do it, and for the path of intel lib, I am obliged to put them in C:\MATLAB6p5\extern\include ?
denham
|
|
|
|
|
You have two option,
1- Copy the lib files in folder of your project.
2- Add the path of Intel library headers and lib files to list of Visual Studio: Tools -> Options -> Directories -> Include & Library combo box
Best regards,
A. Riazi
|
|
|
|
|
When I add #include "nspconv.h" in my mexfunction( like you show me), I have a lot of errors in a nspconv.h, knowing that this header file its programming by intel
I don’t know what I can do !!
Thanks
|
|
|
|
|
Hello!
I'm having a problem when programming a mexfile with visual c++. I have selected a "Win32 Dynamic-Link Library" and everything works fine doing a simple dll. The problem is when including some header files to the mexproject that contains CString objects. Then the compiler says: error C2061: syntax error : identifier 'CString'
Is it not possible to use CStrings in a mexfile and in that case what to do when I'm not able to change the included header files.
Staby
|
|
|
|
|
The fact is the "Win32 Dynamic-Link" doesnt include some header files. Try to include "windows.h" in your stdafx.h and try again.
Best regards,
A. Riazi
|
|
|
|
|
hi All experts,
I am trying my luck here to see whether I could get any help from the experts.
I have 2 files Operation.java and Operation.class.
I can load in the Operation class into Matlab using
>> import Operation
However, when I use the command
>> [M,X,J]=inmem
I do not see the Operation class being loaded. Is there some problem?
I also need to know how do I use the Java objects from that class in Matlab. The Operation.java is as seen below:
/*Operation.java */
/*Purpose:track the properties of operation objects*/
public class Operation{
Operation prevJob = null; //previous operation in a job
Operation nextJob = null; //next operation in a job
private int job;
private int sequence;
private int machine;
private int duration;
private int est;
private int startTime;
//default constructor
public Operation(){
est = 0;
startTime = -1;
}
//constructor
public Operation(int j, int seq, int m, int d){
est = 0;
startTime = -1;
job = j;
sequence = seq;
machine = m;
duration = d;
}
//set the earilest possible start time of an operation
void setEst(int t){
est = t;
}
//sets the actual start time of an operation
void setStartTime(int t){
startTime = t;
}
//allows an opertaion to track the operation that preceeds it
void setPrevious(Operation o){
prevJob = o;
}
//allows an opertaion to track the operation that follows it
void setNext(Operation o){
nextJob = o;
}
//returns the job number of an operation
int getJob(){
return job;
}
//returns the sequence number of an operation
int getSeq(){
return sequence;
}
//returns the machine an operation is on
int getMachine(){
return machine;
}
//returns the earliest possible start time of an operation
int getEst(){
return est;
}
//returns the actual start time of an operation
int getStartTime(){
return startTime;
}
//returns the time an operation has completed its task
int getFinishTime(){
return startTime + duration;
}
//returns the amount of time an opertion nees to complete its task
int getDuration(){
return duration;
}
} //ends Operation Class
|
|
|
|
|
Hi there,
I'd like to interface a (big) dll with matlab. The dll has two available .h interfaces, one in C and one in C++.
I'm wondering what is the best solution.
1) use Matlab Generic DLL Interface.
I've tryed but since the dll functions sometimes need and return complex structure, it's not easy.
2) write a mex file that calls the dll functions through its C interface, and compile it from matlab.
I've tryed as well, but I got a link problem :
timMex.obj : error LNK2001: unresolved external symbol _SNGetCount
where SNGetCount is one of the dll function
3) creating MEX-files in Visual C++.
I haven't tryed yet. Do you think it could solve the link pb? Could I then use the C++ dll interface?
Thanks for your help,
Tim
|
|
|
|
|
Hi,
I suggest you to try the third option. By creating the MEX-files in Visual C++ you have full control on what you want.
Best regards,
A. Riazi
|
|
|
|
|