How do I write a .mat file (exported from the Design Data in an .sldd file) to a csv file?

6 visualizaciones (últimos 30 días)
I am trying to write the contents of a .mat file to a csv file. The .mat file was generated by exporting the Design Data from a simulink data dictionary file that is used in a Simulink model. I've tried to research how to extract the data from the .mat but haven't been able to find anything significant. If you have any suggestions for strategies or functions I could use, please add a comment. Thanks.
CODE:
FileData = load('SLDD_220817.mat');
NewData=struct2cell(FileData);
csvwrite('SLDD_220817.csv', NewData);
CW OUTPUT:
Error using csvwrite (line 47)
The input cell array cannot be converted to a matrix.
Error in sldd_to_csv (line 11)
csvwrite('SLDD_220817.csv', NewData);
  2 comentarios
KSSV
KSSV el 18 de Ag. de 2022
Attach your mat file. It depends on how your data is in the mat file.
Jasmine Dhaliwal
Jasmine Dhaliwal el 12 de Oct. de 2022
Does the "load" function part work? is it just the csvwrite not working? Hard to tell because I don't know which is line 11, I'm sorry TT. I will say also, technically csvwrite isn't recommended- try using writematrix instead!
writematrix(NewData,'wtvName.csv')
^ there's the Help Center link if you wanted to see more about this function!

Iniciar sesión para comentar.

Respuestas (1)

Yash
Yash el 31 de En. de 2025
Editada: Yash el 31 de En. de 2025
Hi Nate,
As the error says "The input cell array cannot be converted to a matrix.", the main reason is that the contents of cell array is having different data types (for example a char and a double). It is therefore unable to convert it to a matrix.
A better approach would be to convert the data to a table instead of a cell array, and write it to csv file using the "writetable" function.
Given below is the updated code:
FileData = load('SLDD_220817.mat');
NewData = struct2table(FileData);
writetable(NewData, 'SLDD_220817.csv');
For more information, refer to the following documentations:

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by