hi.
i am trying to mex(in fortran-matlab).
i want to two values in matlab using mex, i make fortran and put in to 4 mwpointer x-input, y-output, a-input, b-input.
and make fortran files, but it can't read two values.
========================================================================================================
real*8 x, y, A, B, z
C-----------------------------------------------------------------------
if(nrhs .ne. 2) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput',
+ 'One input required.')
elseif(nlhs .gt. 2) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput',
+ 'Too many output arguments.')
endif
if(mxIsNumeric(prhs(2)) .eq. 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric',
+ 'Input must be a number.')
endif
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(2))
size = mrows*ncols
x_ptr = mxGetPr(prhs(1))
A_ptr = mxGetPr(prhs(2))
call mxCopyPtrToReal8(x_ptr,x,size)
call mxCopyPtrToReal8(A_ptr,A,size)
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetPr(plhs(1))
B_ptr = mxGetPr(plhs(2))
call timestwo(y, x, B, A, z)
call mxCopyReal8ToPtr(y,y_ptr,size)
call mxCopyReal8ToPtr(B,B_ptr,size)
return
end
C----------------------------------------------------------------------- C Computational routine
subroutine timestwo(y, x, B, A, z)
real*8 y, x, B, A, z
y = 2.0 * x
B = 2.0 * A
i = y, j = b
z=(i,j)
return
end
======================================================================================================
i'm so hard to understand about prhs,plhs..
is this program correct?
help me please.

3 Kommentare

Chaitra
Chaitra am 27 Jun. 2014
Have you referred to this link?
It gives a description as to how to Create Fortran Source MEX-File.
James Tursa
James Tursa am 27 Jun. 2014
Rather than comment on the multiple problems with the above routine, may I start with asking you what you want it to do? Are you simply trying to input two double scalars, multiply both of them by 2, and then return both of the results back to the MATLAB workspace?
Tejas M U
Tejas M U am 30 Jun. 2014
If you want to understand about prhs, plhs, you may want to refer to the following: http://www.mathworks.com/help/matlab/matlab_external/data-flow-in-fortran-mex-files.html

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 30 Jun. 2014

0 Stimmen

You have created the 1st output by:
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
An equivalent method is required for the 2nd output also, only with plhs(2).

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 26 Jun. 2014

Beantwortet:

Jan
am 30 Jun. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by