Code covered by the BSD License  

Highlights from
xlwrite : Export Data to Excel from Matlab on Mac/Win

3.0

3.0 | 1 rating Rate this file 116 Downloads (last 30 days) File Size: 665 KB File ID: #37560
image thumbnail

xlwrite : Export Data to Excel from Matlab on Mac/Win

by

 

19 Jul 2012 (Updated )

xlwrite allows you to export data (2d/3d arrays of double/cell) to Excel from Matlab (Mac/Win)

| Watch this File

File Information
Description

The function xlwrite has similar syntax and inputs as MatLAB's xlswrite.
It also can write 3-d arrays (xlswrite can't), of cell and double type. To simplify the idea : we forward Matlab data to be exported to a Java function which in turn writes the data to excel.

Note that data to be exported is converted to cell then to java String array.

This workaround is a real working solution, it may need further refinements :
- manage Java heap space, as Java heap memory saturates for large arrays exported many times.
- format dates and strings, as all numbers appear as text in Excel.

Matlab's decimal separator is '.' : in order to be able to work with exported data, users of this solution will have to change Mac preferences regarding the decimal separator (should be ".").
To do so you need to go to System Preferences > International > Formats and click on Customize button in number zone, then type '.' in the field required.
This solution works under Windows.

Test_xlwrite.m contains an example.

Acknowledgements

This file inspired Xlwrite: Generate Xls(X) Files Without Excel On Mac/Linux/Win.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
24 Feb 2014 Joachim Seel

Hi, I have downloaded the xlwrite file but run into this error when trying to run the script below: Any suggestions how to correct this error? Thanks!

Undefined function 'WriteXL' for input arguments of type 'java.lang.String'.

Error in xlwrite (line 68)
WriteXL(java.lang.String(file),Cell2JavaString(data),m(1),m(2));

This is the script.

%define variables
anualbaselineT=5045.2;
anualbaselineX=6902.8;
anualbaselineZ=8773.5;
PVloadratio=1.56;

% read in dynamic load
[dynamic_load_matrix,~,~]=xlsread('../E1_Load_Profile.xlsx','sheet1','C1:Z365');

%pre-allocate for speed
dynamic_load_vector=zeros(8760,1);

% loop through each row of dynamic_load_matrix and append to
% dynamic_load_vector
for i=1:365

dynamic_load_vector((24*i-23):(24*i))=dynamic_load_matrix(i,:);

end

dynamic_load_vector_norm=dynamic_load_vector/sum(dynamic_load_vector);

dynamic_load_baseline_norm(:,1)=dynamic_load_vector_norm*anualbaselineT;
dynamic_load_baseline_norm(:,2)=dynamic_load_vector_norm*anualbaselineX;
dynamic_load_baseline_norm(:,3)=dynamic_load_vector_norm*anualbaselineZ;

dynamic_load_baseline_norm_PV=dynamic_load_baseline_norm*PVloadratio;

header_baseline={'baselineT','baselineX','baselineZ'};
%%
xlwrite('../E1_load_vector.xlsx',header_baseline);

xlwrite('../E1_load_vector.xlsx',header_baseline,'load','A1:C1');
xlwrite('../E1_load_vector.xlsx',dynamic_load_baseline_norm,'load','A2:C366');

xlwrite('../E1_load_vector.xlsx',header_baseline,'load_PV','A1:C1');
xlwrite('../E1_load_vector.xlsx',dynamic_load_baseline_norm,'load_PV','A2:C366');

28 Jul 2013 Edward Byers

Complicated to get started with the java files etc and no very good instructions on this. See the example however.
Doesn't support specifying to a range.
However - support multi-dimensional variables which is a great bonus.

17 Oct 2012 Marin Deresco

@ the cyclist:
check the following submission:
http://www.mathworks.com/matlabcentral/fileexchange/38591

20 Aug 2012 Marin Deresco

@ Paul Shoemaker :
Will try to test a quick solution for xlsread soon (1-2 months).

Regards

06 Aug 2012 Paul Shoemaker

Very neat! Any chance we might see an xlread variant that is similarly cross-platform?

03 Aug 2012 Marin Deresco

@ the cyclist :
Hope xlwrite will help you. Thank you for the remark about the specific cells export. I didn't focus on this point yet. The idea behind xlwrite was to export Matlab 3d arrays of doubles or cells to excel.
If time permits, my next submission will contain currently missing xlswrite features.

02 Aug 2012 the cyclist

This is an exciting submission, as it is an ongoing frustration that xlswrite doesn't function fully on a Mac.

xlwrite doesn't seem to have the ability to write to specific cells on a worksheet, as xlswrite does. Is that something you are planning to add, or is there some fundamental impediment to doing that? It would be a powerful addition.

Updates
24 Jul 2012

updated the summary

03 Aug 2012

According to a user remark, I've updated the description of xlwrite : I've replaced 'same syntax' into 'similar syntax'.

Contact us