Convert .mat to excel file adding column headers
5 ビュー (過去 30 日間)
古いコメントを表示
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?
回答 (1 件)
Vinai Datta Thatiparthi
2020 年 5 月 1 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!