MATLAB error “MFile S-functions without a corresponding TLC file are not supported.”
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LIULIYAN
el 20 de Mayo de 2023
Respondida: Diwakar Diwakar
el 20 de Mayo de 2023
I have written a large number of matrix multiplication in M language. Then, the m file was called using the S-Function module in simulink. Then prepare to compile the Simulink program into an industrial computer. An error occurred during MATLAB compilation, 'MFile S-functions without a corresponding TLC file are not supported.'
May I ask how to solve this problem?
I have an idea that if S-Function is used in Simulink to call C files, there will be no errors during compilation. However, how to use C language to write operations on a large number of matrices?
For example, the transposed product B of matrix A can be written in file m
A=[0,0,0;0,0,-1;0,1,0]; B=[0,0,0;0,0,2;0,4,0]; A'*B
How should I write it in the C file? (Note that I need to implement a lot of matrix operations)
2 comentarios
Walter Roberson
el 20 de Mayo de 2023
I have written a large number of matrix multiplication in M language
Respuesta aceptada
Diwakar Diwakar
el 20 de Mayo de 2023
The error you encountered during MATLAB compilation is because M-files (files with the .m extension) used as S-Functions in Simulink require a corresponding TLC (Target Language Compiler) file for compilation, which seems to be missing in your case.
To resolve this issue, you have a few options:
1. Provide a TLC file: You can create a TLC file for your M-file S-Function to enable compilation. The TLC file contains instructions for code generation from your M-file. The TLC file extension is .tlc. You can find more information on how to create a TLC file in the MATLAB documentation.
2. Convert M-file to C: Instead of using an M-file S-Function, you can convert your M-file code to C code. MATLAB provides the "matlabFunction" function that can generate C code from MATLAB code. This way, you can directly use the generated C code in your S-Function.
To write the matrix operation you mentioned (`A'*B`) in C, you can follow these steps:
1. Use the "matlabFunction" function in MATLAB to generate the C code for the desired matrix operation. Here's an example of how you can do it:
%matlab
syms A B;
output = A'*B;
codegen -config:lib output -args {A, B}
```
This will generate C code for the matrix operation and save it in a folder, along with other required files.
2. Create a new C file in your preferred development environment (e.g., using a text editor or an Integrated Development Environment like Visual Studio).
3. Open the generated C code from step 1 and copy the necessary function(s) into your new C file.
4. Modify the C code as needed to fit the structure of your S-Function in Simulink. This may include adding appropriate input/output arguments and handling data types.
5. Once you have written the necessary C functions for your matrix operations, you can use them in your S-Function in Simulink.
Note that converting MATLAB code to C code may not be a straightforward process, especially for complex operations or functions. You may need to modify the generated code and add additional error handling, memory management, and other necessary components.
Also, keep in mind that writing a large number of matrix operations in C manually can be time-consuming and error-prone. Consider using appropriate libraries or frameworks for matrix operations in C, such as LAPACK or Eigen, to simplify the implementation and benefit from optimized and reliable matrix computation routines.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Target Language Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!