x = 2;
y = timestwo(x)
y =
4
and I experience the following error:
??? Error using ==> timestwo
MEX level2 S-function "timestwo" must be called with at least 4 right
hand arguments
So I try to be clever and put more arguments to function:
y = timestwo(1,1,0,0) and it
I use Matlab version:
MATLAB Version 7.6.0.324 (R2008a)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600:
Service Pack 3)
Java VM Version: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot
(TM) Client VM mixed mode
And here is code from example from Matlab that I am trying to run:
#include "mex.h"
/*
* timestwoalt.c - example found in API guide
*
* use mxGetScalar to return the values of scalars instead of pointers
* to copies of scalar variables.
*
* This is a MEX-file for MATLAB.
* Copyright 1984-2000 The MathWorks, Inc.
*/
/* $Revision: 1.6 $ */
void timestwo_alt(double *y, double x)
{
*y = 2.0*x;
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *y;
double x;
/* Check arguments */
if (nrhs != 1) {
mexErrMsgTxt("One input argument required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
} else if (!mxIsNumeric(prhs[0])) {
mexErrMsgTxt("Argument must be numeric.");
} else if (mxGetNumberOfElements(prhs[0]) != 1 || mxIsComplex(prhs
[0])) {
mexErrMsgTxt("Argument must be non-complex scalar.");
}
/* create a 1-by-1 matrix for the return argument */
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
/* get the scalar value of the input x */
/* note: mxGetScalar returns a value, not a pointer */
x = mxGetScalar(prhs[0]);
/* assign a pointer to the output */
y = mxGetPr(plhs[0]);
/* call the timestwo_alt subroutine */
timestwo_alt(y,x);
}
Regards
Ryszard
What compiler and system etc do you use?
Rune
As I have written in my query I use Matlab version:
MATLAB Version 7.6.0.324 (R2008a)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600:
Service Pack 3)
Java VM Version: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot
(TM) Client VM mixed mode
Is the name of the MEX-file that you created timestwo.mexw32 or
timestwoalt.mexw32? There's an example C MEX S-function called timestwo,
and it looks like MATLAB thinks you're trying to invoke that S-function
rather the MEX-file you built:
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/f8-94774.html
It looks like the basic example in the MEX documentation is also called
timestwo, and I think that could probably cause confusion. I'll mention
that to the MEX documentation staff.
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f23674.html
As the instructions at the bottom of the page states, you might want to copy
the timestwo example you're working on to a work folder (and perhaps call it
timestwoalt), as then even if you call it timestwo just like the S-function,
since it's in the current directory it will be used instead of the
S-function version.
*snip*
--
Steve Lord
sl...@mathworks.com
Although I copied a code from timestwoalt I was compiling and using
timestwo as timestwo.
Now I understand most of my mistakes, but thats only the beginning of
my path because I am willing to be able to run my c++ code (ie
exchange data) with structures and classes from matlab as well as from
some free 3rd part stuff, so wish me good luck
Thanks again
Ryszard
On Dec 3, 6:23 pm, "Steven Lord" <sl...@mathworks.com> wrote:
> <r.p.mac...@googlemail.com> wrote in message
>
> news:7b121f62-26c6-4eca...@w35g2000yqm.googlegroups.com...
>
>
>
> > Hi,
> > I have some C code to be run from already written Matlab program.
> > I tried to follow example from help: Examples of C Source MEX-Files: A
> > First Example — Passing a Scalar.
> > It compiles fine.
> > I try to run example as it is described in help:
>
> > x = 2;
> > y = timestwo(x)
> > y =
> > 4
>
> > and I experience the following error:
>
> > ??? Error using ==> timestwo
> > MEX level2 S-function "timestwo" must be called with at least 4 right
> > hand arguments
>
> Is the name of the MEX-file that you created timestwo.mexw32 or
> timestwoalt.mexw32? There's an example C MEX S-function called timestwo,
> and it looks like MATLAB thinks you're trying to invoke that S-function
> rather the MEX-file you built:
>
> http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/f8...
>
> It looks like the basic example in the MEX documentation is also called
> timestwo, and I think that could probably cause confusion. I'll mention
> that to the MEX documentation staff.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external...