Accessing handle graphics from within Fortran mexfunction

Can you access Matlab's handle graphics from within a Fortran mexFunction? I see that there are mexSet and mexGet functions; however, they appear to apply only for C mexFunctions.
Thanks a million, Bill

 採用された回答

Titus Edelhofer
Titus Edelhofer 2011 年 8 月 15 日

1 投票

Hi Otis,
I guess (!) the answer is yes. Handles itself are just usual doubles. Therefore you should be able to call the set and get by something like
mxArray* pprhs[3];
pprhs[0] = prhs[0]; // assuming prhs[0] is the handle
pprhs[1] = mxCreateString("tag");
pprhs[2] = mxCreateString("Bill");
mexCallMATLAB(0, plhs, 3, pprhs, "set");
Titus

5 件のコメント

Jan
Jan 2011 年 8 月 15 日
@Titus: I assume you want:
"pprhs[0] = mxDuplicateArray(prhs[0])" and "mexCallMATLAB(0, NULL, 3, pprhs, "set");"
But this is still C, while Otis asks for Fortran.
@Otis: You are right - the documentation tells, that mexSet and mexGet are available for C only. This is surprising, because I do not see a reason to forbid this from Fortran. However, Titus' mexCallMATLAB is a working solution, although it is much slower than mexSet.
Otis
Otis 2011 年 8 月 15 日
@Titus ... Thanks!!!!!!!!!!!!!!!!!!
I tried your approach with the following simple test and it worked!!
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
integer*4 :: nlhs, nrhs, nnlhs, nnrhs
integer*4 :: plhs(nlhs), prhs(nrhs)
integer*4 :: mxCreateString
integer*4, dimension(3) :: pplhs, pprhs
if (nrhs .ne. 1) then
call mexErrMsgTxt('One input argument required.')
else if(nlhs .ne. 0) then
call mexErrMsgTxt('No output arguments required.')
end if
nnlhs = 0
pplhs(1) = 0
pplhs(2) = 0
pplhs(3) = 0
nnrhs = 3
pprhs(1) = prhs(1)
pprhs(2) = mxCreateString("String")
pprhs(3) = mxCreateString("Rush Rocks!!")
call mexCallMATLAB(nnlhs, pplhs, nnrhs, pprhs, "set")
return
end
Thanks again,
Bill
Titus Edelhofer
Titus Edelhofer 2011 年 8 月 15 日
Hi Bill,
your welcome. And sorry for mixing up Fortran and C, fortunately you and Jan noticed ;-).
Titus
Jan
Jan 2011 年 8 月 15 日
@Titus: Please fix the prhs->pprhs confusion in your code. The line "prhs[0] = mxDuplicateArray(prhs[0])" will blow-up the memory manager...
Titus Edelhofer
Titus Edelhofer 2011 年 8 月 15 日
Hi Jan,
thanks for the reminder, done ...
Titus

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2011 年 8 月 15 日

0 投票

You can get Fortran versions of mexGet and mexSet in my Fortran 95 interface package, which can be found here:
They work the same as their C counterparts. You can also find a lot of other useful functions & utilities in this package, many of which are not available in the C API.

1 件のコメント

Otis
Otis 2011 年 8 月 15 日
@James ... Cool!! I will definitely check it out. Thanks!!
Bill

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFortran with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by