writing a mex statement for outputting values of some variables to the console.

2 ビュー (過去 30 日間)
Magdy Hanna
Magdy Hanna 2025 年 3 月 16 日
コメント済み: James Tursa 2025 年 3 月 18 日
I am preparing a MEX file.
I want to output the values of some variables to the console.
What MEX statement can do that for me?
  2 件のコメント
dpb
dpb 2025 年 3 月 16 日
Insufficient data...MEX routines are simply the glue layer between the alternate language and MATLAB, the functionality is written with the other language -- so in Fortran you would use write statements, in C the fprintf library function.
Magdy Hanna
Magdy Hanna 2025 年 3 月 16 日
How can I specify the console as the output medium?
Using write(6 , *) did not work.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 3 月 16 日
#include "fintrf.h"
integer*4 mexPrintf(message)
character*(*) message
You would prepare the message into a character variable ahead of time, by using WRITE to the character variable. See for example https://stackoverflow.com/questions/5808034/how-to-write-output-to-a-string-in-fortran
  1 件のコメント
James Tursa
James Tursa 2025 年 3 月 18 日
Also note that you need to add the newline manually. E.g., something like this (CAUTION: UNTESTED)
#include "fintrf.h"
integer*4, external :: mexPrintf
integer*4 result
character*50 message
integer :: myvariable = 123
write(message,*) myvariable
result = mexPrintf( message // achar(10) ) ! adding a line feed

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

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by