Export certain cells of a structure into a table (.csv file)

25 views (last 30 days)
I'm using Matlab2015a -- I cannot attach the data structure because the file is too large
My data is in a 1x80 struct with 68 fields.Each cell contains data as an nx1 double (data in .mat format here: https://merced-my.sharepoint.com/:u:/g/personal/jkaur28_ucmerced_edu/ET489-KS_lJEoI5dUabFTX4B8wUcIf6_cT2kuS0QXIuteA).
For every row in the structure, I want to extract the values from in each cell in one column a table. So for the row called Field 1, I want a table with columns Right_HandX, RightHandY, RightHandXVec...etc and rows 1:number of values in the cell.
I want to end up with 80 tables for each of these structures, which I can write to separate csv files.
I have used T = struct2table(trials) and it makes a table that looks identical to the structure. I've also tried cell2table(trials) which did the same thing. Once I have the data organized in the correct format I can easily use writetable(T, filename) to save as a csv. I just need help getting the data out of the structure and into a well organized table.
  4 Comments
Arif Hoq
Arif Hoq on 30 Jan 2022
I think you can use a drive to upload your file(as it's large) and please provide the drive link.

Sign in to comment.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 30 Jan 2022
One quick solution with your large data to separate them and write to an external file is the following in the example of two field variables, viz. Right_HandX and Right_HandY:
load('trials.mat');
FN='Data.xlsx';
for ii=1:80
X = trials(ii).Right_HandX;
Y = trials(ii).Right_HandY;
writematrix([X,Y],FN,'Sheet',ii)
end
This is how you can take out every column of your data and write them to an external file, e.g.: MS Excel or .txt or .dat or .csv

More Answers (0)

Categories

Find more on Data Type Conversion 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!