User`s guide

Print Handlers
5-49
mrank.m determines the rank of the magic squares from 1 to n.
function r = mrank(n)
r = zeros(n, 1);
for k = 1:n
r(k) = rank(magic(k));
end
myph.c contains the print handler and the print handler initialization
routine, in that order. In the example, this C file is written by the user.
#include "matlab.h"
#include “mr_external.h”
static void myPrintHandler(const char *s)
{
printf("%s\n",s);
}
void Mmr_initprnt(void)
{
mlfSetPrintHandler(myPrintHandler);
}
Writing the Print Handler in C/C++
First, write a print handler in C following the standard rules for a print
handler: it must take one argument of type
const char *s and return void.
The p rint handler in this e xample is very simple.
static void myPrintHandler(const char *s)
{
printf("%s\n",s);
}
The file myph.c contains this code.
Registering the Print Handler
Registering the print handler requires several steps, some performed in C and
some in M. Be careful to name your C and M print handler initialization
functions according to the rules presented below. Otherwise, the
correspondence between the two is missing.