First up, we are going to look at a simple MATLAB program calculating mean values of 10 numbers. Then we will set a code generation project in MATLAB to generate C code from the MATLAB program and compile the C code in Eclipse.
MATLAB provides a very powerful high-level programming language, known as m-language or m-script, for numerical computation and data processing. We are going to go through the following steps and quickly take a look at a very simple program written in the MATLAB m-language:
Launch MATLAB and create a folder (for example,
C:\myMatlab
) as your working folder to save your MATLAB code and project files.Navigate to your working folder that we just created, through File | New | Function to create an empty MATLAB script file
calcavg.m
. Type in the following code in the text editor and save it tocalcavg.m
:function avg = calcavg(a) %#codegen avg=mean(a);
Here, variable
a
is the input argument that indeed is an array storing 10 numbers...