FMU Export with .csv as input

1 Comment
Hi Sharul Baggio,
The error message you received indicates that the "From Spreadsheet" block is not compatible with the FMU export process in certain configurations. To work around this limitation, consider using a different approach for input handling. One alternative is to utilize a MATLAB function block that reads the spreadsheet data at runtime. This block can be designed to accept user-uploaded files, allowing for dynamic input during simulation.
function data = readSpreadsheet(filePath)
% Read data from the specified spreadsheet file
data = readtable(filePath);
end
You can then call this function within your model to load the data dynamically. Hope, this method should help resolve your issue. Please let me know if you have any further questions.
Answers (4)
1 vote
1 Comment
Hi @ Sharul Baggio,
That is frustrating. It sounds like these certain MATLAB functions which you tried including readtable, readCSV, and csvread, are not designed to be used in code that is generated for deployment or simulation in environments that do not support these functions. I just went through documentation
https://www.mathworks.com/help/matlab/ref/csvread.html
it mentions that csv not recommended, you have to use read matrix for R2019a and above. Here is documentation for read matrix
https://www.mathworks.com/help/matlab/ref/readmatrix.html
Also, this documentation below shows supported file format for export and import
Also, instead of using unsupported functions for code generation, consider importing data directly through Simulink blocks designed for this purpose. Use blocks like From Spreadsheet or From File that can read data without relying on unsupported MATLAB functions. If you have data stored in CSV format, you can convert it into a format compatible with Simulink, such as using a Constant block to feed in predefined values or using MATLAB Function blocks with compatible coding practices. This is the last alternative to try, Set your model to use a fixed-step solver:
set_param('your_model_name', 'Solver', 'FixedStepAuto')Use the exportToFMU function correctly by specifying necessary parameters:
exportToFMU('your_model_name', 'FMIVersion', '3.0', 'FMUType', 'CS')Make sure that any variable inputs or outputs are properly defined and that their data types are compatible with FMI standards.
If you continue to face issues, consider simplifying your model incrementally and testing exports until you isolate the source of errors.
0 votes
0 votes
2 Comments
Categories
Find more on FMU Importing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!