How to export a cell matrix into a MS Excel file

3 次查看(过去 30 天)
Attached is a cell array which I would like to export into a MS Excel spreasheet where each row correspond to one (of 12) years and would represent a tab inside that Excel file. Each of the 8 columns (or variables) would represent a column inside each tab.
I know this can be done with the 'xlswrite' command (see here for an example). But that command has now been superseded by the 'writecell' command, which I have problems with. Thanks!
  3 个评论
Dyuman Joshi
Dyuman Joshi 2023-12-8
编辑:Dyuman Joshi 2023-12-8
What problems did you encounter with writecell?
And which array from the following list are you trying to save? ans?
z = load("THRESH_DATA.mat")
z = struct with fields:
DATA_ISI: {12×1 cell} DATE: [23060×1 datetime] DATES_ECCC: [12×4 double] DATE_ISI: [2868×1 datetime] DATE_RANGE_ECCC: [23×4 double] DATE_RANGE_ISI: [12×4 double] DAY: [23060×1 double] D_YEAR_ISI: {12×1 cell} ECCC_File: [23060×36 table] FDD_Fall: [12×1 double] FIRST_1_CB: [12×2 double] ISI_File: [2868×24 table] ISI_NUMBER: [2868×1 double] ISIdata_CBeauharnois: 1 ISIdata_LakeStLawrence: 0 MAX_TP: [23060×1 double] MEAN_TP: [23060×1 double] MIN_TP: [23060×1 double] MONTH: [23060×1 double] STARTYEAR: [2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011] THRESH_DATA: {12×8 cell} YEAR: [23060×1 double] a: [1×1 TiledChartLayout] ans: {[110×1 datetime] [110×1 double] [110×1 double] [110×1 double] [110×1 double] [110×1 double] [110×1 double] [110×1 double]} aver_CB_0to1: 51.5056 aver_CB_1to2: 96.9560 aver_CB_to0: 27.3914 aver_LSL_0to1: 80.5893 aver_LSL_1to2: 104.3250 aver_LSL_to0: 32.7929 ax: [1×1 Axes] bstfit2: [3.8500 -7.2983e+04] coeff_CB: [1.6133 -3.0864e+03] coeff_LSL: [3.1997 -6.1568e+03] dumISI: [12×1 double] end_day: 20-Mar-2012 end_day_ini: 20 end_day_isi: 20-Mar-2012 end_month: 3 firstISI: [12×1 double] idx_year: 12 init: 0 k: 10 m: 62 n: 12 no_days_AirTemp: 10 p_ISI: [1×1 struct] p_ISI_model: [1×12 Line] p_ISI_obs: [1×12 Line] sl_bst: 5 slope: 1.6133 slope_CB_0to1: -0.7768 slope_CB_1to2: -0.6994 slope_CB_to0: 0.9104 slope_LSL_0to1: -1.2459 slope_LSL_1to2: 1.1121 slope_LSL_to0: 0.4805 start_day: 01-Dec-2011 start_day_ISI: 1 start_day_isi: 01-Dec-2011 start_month_ISI: 12 start_year: 2000 temperature_DD: 0 temporary_DD: 18 thresh1: 10 thresh2: 20 y_intercept: -3.0864e+03 yearcount: 12
Paul Barrette
Paul Barrette 2023-12-8
Thanks, @Dyuman Joshi. I had NO idea THRESH_DATA.mat contained so many variables! (I thought it was only 'THRESH_DATA', which is what I'm interested in). As for the problems in using 'writecell', it was mostly about sorting out the differences between [ vs { vs ( in the script. The Documentation is written for programming-savvy folks.

请先登录,再进行评论。

采纳的回答

Voss
Voss 2023-12-8
filename = 'test_THRESH_DATA.xlsx';
N = size(THRESH_DATA,1);
for ii = 1:N
T = table(THRESH_DATA{ii,:});
writetable(T,filename,'Sheet',ii,'WriteVariableNames',false);
end
  3 个评论
Paul Barrette
Paul Barrette 2023-12-8
移动:Dyuman Joshi 2023-12-8
Thanks, @Voss. That's exactly what I was looking for.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by