How can I exchange .mat file input data to spreadsheet excel file programatically?

I am looking for a way to programmatically export the input data for the test patterns from the .mat file loaded into Test Manager to an Excel file of type sltest.io.SimulinkTestSpreadsheet in Simulink Test R2023a.
Currently, I am performing this task using the Test Manager menu via the Signal Editor. However, I want to perform this task using commands.

 采纳的回答

The class sltest.io.SimulinkTestSpreadsheet inherits from the class Simulink.io.FileType . This base class has an import/export methods which can also be leveraged with sltest.io.SimulinkTestSpreadsheet. 
Please see this example: https://www.mathworks.com/help/simulink/slref/simulink.io.filetype-class.html#mw_c40e57e4-e5c0-44d9-a15b-aaf78c04b476
https://www.mathworks.com/help/simulink/slref/simulink.io.filetype.exportimpl.html
There is no direct way to convert a MAT to Excel, but similar to the workflow used by you, this can be broken up into a two step process
1. Load the MAT file into a dataset or individual signals
2. Then export this to Excel
I am not showing Step 1 since there are many ways to do so. But let's say you create a Simulink.SimulationData.Dataset, here is one example (similar to the published example):
ds = Simulink.SimulationData.Dataset;
ds = ds.addElement(timeseries([1:10]',[1:10]'),'Siganl1');
ds = ds.addElement(timeseries([1:10]',[11:20]'),'Siganl2');
ds = ds.addElement(timeseries([1:10]',[21:30]'),'Siganl3');
reader = sltest.io.SimulinkTestSpreadsheet('slt_excel.xlsx');
reader.export('slt_excel.xlsx',{'ds'},{ds},0);

更多回答(0 个)

产品

版本

R2023a

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by