convert time series struct to csv file

조회 수: 82 (최근 30일)
Davindra Usov
Davindra Usov 2023년 1월 17일
댓글: Davindra Usov 2023년 1월 19일
Hello,
I have a 1x1 struct called 'fluid_data' with 13 fields where each field is a 400000 x 1 timetable. In each field, there is a 'time' column and a quantity column e.g. 'viscosity'. These headings are in the field.
I am trying to make this into a csv file called "my_csv_file" with this code but it will not accept timeseries
fluid_data = load('property_values.mat');
writestruct(fluid_data,"my_csv_file.csv");
'property_values.mat' is an output file I created earlier in the code. This contains simulink timeseries data. So I am converting this file into a struct called 'fluid_data' and then converting this into a csv file called "my_csv_file"
Thank you

채택된 답변

Gowthami
Gowthami 2023년 1월 18일
Hi Davindra,
It is my understanding that you trying to convert a MAT file to a CSV file when the MAT file has structures in it.
If the MAT file contains a structure, we would not know which fields to save into the CSV file.
One possible solution is to load the MAT file to the MATLAB Workspace, then convert the structure to a table. For example, if the MAT file has the following structure:
>> S.Name = {'CLARK';'BROWN';'MARTIN'};
>> S.Gender = {'M';'F';'M'};
>> S.SystolicBP = [124;122;130];
>> S.DiastolicBP = [93;80;92];
You can convert the structure array to table and then use the "writetable" function to write the table to a CSV file, as follows:
>> T = struct2table(S)
>> writetable(T,'test.csv')
Please refer to the following link for more information on using the "writetable" function: https://www.mathworks.com/help/matlab/ref/writetable.html
  댓글 수: 1
Davindra Usov
Davindra Usov 2023년 1월 19일
Hi Gowthami,
This is exactly what I ended up doing
many thanks for your help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by