Clear Filters
Clear Filters

How to export a cell matrix into a MS Excel file

6 views (last 30 days)
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 Comments
Dyuman Joshi
Dyuman Joshi on 8 Dec 2023
Edited: Dyuman Joshi on 8 Dec 2023
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 on 8 Dec 2023
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.

Sign in to comment.

Accepted Answer

Voss
Voss on 8 Dec 2023
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 Comments
Paul Barrette
Paul Barrette on 8 Dec 2023
Moved: Dyuman Joshi on 8 Dec 2023
Thanks, @Voss. That's exactly what I was looking for.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!