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

Chaitra
Chaitra 2014년 6월 27일
Have you referred to this link?
It gives a description as to how to Create Fortran Source MEX-File.
James Tursa
James Tursa 2014년 6월 27일
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 2014년 6월 30일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2014년 6월 30일

0 개 추천

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).

카테고리

도움말 센터File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

제품

질문:

2014년 6월 26일

답변:

Jan
2014년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by