Convert .mat to excel file adding column headers
5 views (last 30 days)
Show older comments
I am trying to convert a .mat file to an excel file, and during this is would like to add headers to the columns of the excel sheet.
my .mat file has 3 variables (a,b,c) and I would like each variable to have its own sheet in the excel file.
I would like the headers of 'sheet a' to be (time, distance, speed), 'sheet b' to be (time, acceleration, force) and 'sheet c' to be (time, lift, drag)
How would i do this?
Answers (1)
Vinai Datta Thatiparthi
on 1 May 2020
Hey Callum,
% Since the .mat file was not provided, I'm generating a bunch of random numbers for the variables
a = randi(10,[10,3]);
b = randi(10,[10,3]);
c = randi(10,[10,3]);
% Cell array of headers corresponding to the variables
headerA = {'time','distance','speed'};
headerB = {'time','acceleration','force'};
headerC = {'time','lift','drag'};
% Create a cell array containing both the data and the headers
out = cell(1,3);
out{1} = [headerA; num2cell(a)];
out{2} = [headerB; num2cell(b)];
out{3} = [headerC; num2cell(c)];
% Use the function 'writecell' to export your data into an Excel sheet
for idx=1:3
writecell(out{idx},'test.xlsx','Sheet',idx);
end
Find the Documentation for writecell here: LINK
Hope this helps!
0 Comments
See Also
Categories
Find more on Spreadsheets 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!