4.5. RUNNING MATLAB CODER-GENERATED C CODES ON SMARTPHONES 99
is function calls the function L4_1, where the five output arrays x1 , x2 , y , and y_ac ,
and MSE are returned. To assign y data values to Array, a temporary array called y_temp is
used in a for loop and is filled by y data values:
int i;
double y_temp[length];
for( i = 0; i < length; i++) {
y_temp[i] = y->data[i];
// __android_log_print(ANDROID_LOG_ERROR,
// "HelloWorld Final 1", "%f ", y_temp[i]);
}
Note that for MSE , this step is not needed since it is only one value.
Next, free the allocated memory by copying the following lines from the file main.c:
emxDestroyArray_real32_T(y_ac);
emxDestroyArray_real32_T(y);
emxDestroyArray_real32_T(x2);
emxDestroyArray_real32_T(x1);
Assign y_temp to Array and return it:
(*env)->SetDoubleArrayRegion(env,jArray,0,length,y_temp);
return jArray;
}
ese steps need to be repeated for all the defined outputs in the function L4_1; see the shell
provided for L4_1.
9. Finally, design your desired GUI. is link provides guidelines as how to design GUIs:
http://androidplot.com/docs/quickstart/
4.5.2 RUNNING ON iOS SMARTPHONES
is section covers the steps for integrating a C code generated by the MATLAB Coder into
the Xcode shell previously covered for running it on iPhone smartphones. ese steps are listed
below.
1. Create the shell.
2. Verify the MATLAB function to be run.
100 4. LINEAR TIME-INVARIANT SYSTEMS AND CONVOLUTION
3. Use the MATLAB Coder to generate the corresponding C code to be placed in the shell.
4. Modify the shell to integrate the C code into it.
e first three steps were covered previously in the Android section and are the same
for iOS. In this section, the fourth step is covered. Let us consider the lab L4_1 shell and its
corresponding C code generated by the MATLAB Coder. e following modifications of the
shell are needed for running the code on an iOS smartphone.
Here it is worth mentioning that the group structure in Xcode is not the same as the folder
structure in Finder on Mac. It can be made to be the same, but making a group does not make
a relative folder on the file system.
5. Make the directory codegen/lib/L4_1 as a subfolder in the Xcode project L4_1.
6. Navigate to the folder created by the MATLAB Coder named codegenlibL4_1. Copy all
the files with the extensions .h and .c to the Xcode project.
7. In the Xcode Project Navigator, click on File ! Add Files to “L4_1”.
8. Click File ! New ! Group and type in “Native Code”.
9. Select all of the .c and .h files and drag them into the “Native Code” group.
e MATLAB C codes will be built and get ready for use. e code to interact with buttons
and graphs was covered earlier. Now, the generated C code needs to get placed or integrated
into the iOS shell.
Click on ViewController.m” to edit the file. At the top of the file above the interface
definition, import the following necessary header files:
#import ``ViewController.h''
#import ``L4_1.h''
#import ``L4_1_emxAPI.h
Underneath the line, in the buttonPress method,
int length = round( 8.0 / delta);
add the following lines:
if( _x1 == NULL )
{
_x1 = emxCreate_real32_T(1,length);
}
if( _x2 == NULL )
{
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.16.254