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

6 ビュー (過去 30 日間)
Nate Rutter
Nate Rutter 2022 年 8 月 17 日
編集済み: Yash 2025 年 1 月 31 日
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 件のコメント
KSSV
KSSV 2022 年 8 月 18 日
Attach your mat file. It depends on how your data is in the mat file.
Jasmine Dhaliwal
Jasmine Dhaliwal 2022 年 10 月 12 日
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!

サインインしてコメントする。

回答 (1 件)

Yash
Yash 2025 年 1 月 31 日
編集済み: Yash 2025 年 1 月 31 日
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:

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by