import
in MATLAB FunctionsIf you use the import
command in a MATLAB® function,
add the corresponding .NET assembly before calling the function. For
example, the following function getPrinterInfo
calls
methods in the System.Drawing
namespace.
function ptr = getPrinterInfo import System.Drawing.Printing.*; ptr = PrinterSettings; end
To call the function, type:
NET.addAssembly('System.Drawing'); printer = getPrinterInfo;
Do not add the command NET.addAssembly('System.Drawing')
to
the getPrinterInfo
function. MATLAB processes
the getPrinterInfo.m
code before executing the NET.addAssembly
command.
In that case, PrinterSettings
is not fully qualified
and MATLAB does not recognize the name.
Likewise, the scope of the import
command
is limited to the getPrinterInfo
function. At the
command line, type:
ptr = PrinterSettings;
Undefined function or variable 'PrinterSettings'.