MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE Uživatelská příručka Strana 93

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 354
  • Tabulka s obsahem
  • ŘEŠENÍ PROBLÉMŮ
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 92
Interfacing M-Co de to C/C++ Code
Inter facing M -Code to C/C++ Code
In this section...
“Overview” on page 5-13
“C Ex ample” on page 5-13
Overview
MATLAB Compiler supports calling arbitrary C/C++ functions from your
M-code. You simply provide an M-function stub that determines how the code
will be have in M, and then provide an implementation of the body of the
function in C or C++.
CExample
Suppose you have a C function that reads data from a measurement
device. In M-code, you want to simulate the device by providing a sine
wave output. In production, you want to provide a function that returns
the meas urement obtained from the device. You have a C function called
measure_from_device() that returns a double, which is the current
measurement.
collect.m containstheM-codeforthesimulation of your application.
function collect
y = zeros(1, 100); %Preallocate the matrix
for i = 1:100
y(i) = collect_one;
end
disp (y)
function y = collect_one
persistent t;
if (isempty(t))
t=0;
end
5-13
Zobrazit stránku 92
1 2 ... 88 89 90 91 92 93 94 95 96 97 98 ... 353 354

Komentáře k této Příručce

Žádné komentáře