matlab multidimensional array to excel

I have a Matlab script with an output of a multidimensional array LCOE (3 dimensions) of size 16:12:34. This output needs to be written to Excel, therefore I use xlswrite.

I have tried this:

  • Eliminate duplicates and Insert Unique records having max no. of column values present through Talend
  • Loop through rows and select dynamic range of columns to edit
  • excel solver add in gives the answer but Solver Foundation doesn't produce any answer
  • Workbooks.close stopping macros completely
  • How to increase columns in PHP excel
  • Python - xlrd and unicodecsv
  • T = LCOE(:,:,1);
    xlswrite('filename', T, 'sheetname', 'B2');

    This does what it’s supposed to, but only writes one table to excel, and I would like to write all 34 tables to excel underneath each other, spaced by `2 blank rows.

    Then, I tried this:

    for y = 1:34
        T = LCOE(:,:,y)
        xlswrite('filename', T, 'sheetname', strcat('B', num2str(2+(y-1)*18)));

    This works, but is very slow, since matlab writes each table separately to excel. Is there a faster way to do this?

  • A faster way to compare text from different columns
  • Title box bug when copying slide to another presentation
  • How to update data using vba excel
  • What potentially harmful circumstance is avoided by assigning true to Excel's ApplicationClass' UserControl member?
  • Line Chart using Arrays instead of Range
  • Return Adjacent Cell Value from Max Value of Duplicates
  • One Solution collect form web for “matlab multidimensional array to excel”

    Instead of using xlswrite again and again. Dump all the values of a 3D matrix into a 2D matrix and add rows of NaNs so that when you write that to excel file, you get 2 blank rows.

    Following code improves the execution time by the factor of more than 10.

    LCOE = 100*rand(16,12,34);   % Taking random values for LCOE
    T = NaN(18*34-2 ,12);        % 1. Pre-allocation    2. 16+2 = 18 
    % Following loop dumps all the values of 3D matrix into a 2-D followed by 2 rows of NaN 
    % to leave 2 blank rows in excel file. 
    for k = 1:34
        T(18*(k-1)+[1:16], :) =  LCOE(:,:,k); 
    xlswrite('filename', T, 'sheetname', 'B2'); % Writing the Excel file

    In my system, my code takes about 1 second to execute while your code takes about 10.5 seconds. So that’s a significant difference.

    MS Excel Spreadsheet is the best Office Software, Excel VBA and Excel Formulas make Spreadsheet work faster.