Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
mexfunction

Subject: mexfunction

From: Elnaz

Date: 7 Apr, 2013 21:56:05

Message: 1 of 3

Hi all,

My function defined in C has two outputs but when I call it from MATLAB command line it only returns the first output.
I am calling mexfunction gateway for my 3 input, 2 output function as:
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
  double *in1, *in2, *out1, *out2;
  int in3;
  size_t mrows,ncols;
  mrows=mxGetM(prhs[0]); ncols=mxGetN(prhs[0]);
  length = (int) ncols;
  /* Create matrix for the return argument. */
  plhs[0] = mxCreateDoubleMatrix((mwSize)mrows, (mwSize)ncols, mxREAL);
  plhs[1] = mxCreateDoubleMatrix((mwSize)mrows, (mwSize)ncols, mxREAL);
  
  /* Assign pointers to each input and output. */
  in1= mxGetPr(prhs[0]);
  in2= mxGetPr(prhs[1]);
  out1= mxGetPr(plhs[0]);
  out2= mxGetPr(plhs[1]);

  /* Call the bcjr_decoder subroutine. */
  my-func(in1, in2, in3, out1, out2);
}

How can I get it to return the both?

Thanks,
Elnaz

Subject: mexfunction

From: Bruno Luong

Date: 8 Apr, 2013 06:22:10

Message: 2 of 3

"Elnaz " <ebsadeghian@gmail.com> wrote in message
>
> My function defined in C has two outputs but when I call it from MATLAB command line [snip]...

How?

Bruno

Subject: mexfunction

From: James Tursa

Date: 8 Apr, 2013 06:39:10

Message: 3 of 3

"Elnaz " <ebsadeghian@gmail.com> wrote in message <kjsq1l$akk$1@newscl01ah.mathworks.com>...
>
> My function defined in C has two outputs but when I call it from MATLAB command line it only returns the first output.
> I am calling mexfunction gateway for my 3 input, 2 output function as:

(snip)

> How can I get it to return the both?

[x y] = mymexfunction(a,b,c)

However, to keep from getting a seg fault and crashing MATLAB, you really should have a test for nlhs==2 in your code before you write into plhs[1].

James Tursa

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us