Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Saving Data from MATLAB to Excel Using a Template 6

Posted by Stuart McGarrity,

I often need to export data from MATLAB to Excel. As the files are used by others, I like to format them nicely for easy viewing and browsing. To do this, I simply create a spreadsheet with all the required formatting as a template and copy it each time.

Play the video in full screen mode for a better viewing experience.

6 CommentsOldest to Newest

Oren Rosen replied on : 1 of 6
Thanks for the video Stuart. I am constantly writing data to Excel and formatting columns, freezing panes etc., but rarely do I have the same number and order of columns, so templates are a limited solution. What I would recommend as a valuable addition to MATLAB would be to allow for automatic formatting of columns via COM as you mentioned, with individual column formats specified in table properties similar to what something like sprint uses, i.e. %s, %0.2f, etc. I have built a solution like this for our internal use for writing dataset arrays to html tables that can automatically be included via cell mode publishing and it is quite useful.
Stuart McGarrity replied on : 2 of 6
Hi Oren, Good to hear from you. I agree, I'd like something like what you describe. I passed your idea on to others looking at this area.
Lucie SOMAGLINO replied on : 3 of 6
Hi, thanks for the great video, it's very useful. Everything works great for me except the width of the columns that doesn't stay when I copy the table to the formatted file (I do exactly the same as you do). Have you or somebody ever experienced this? Any solution? Thanks in advance,
Stuart McGarrity replied on : 4 of 6
Hi Lucie, In a recent release of MATLAB a feature was introduced that auto-adjusts the column widths to match the data. To stop this, the only current option is to comment out a line in writeXLSFile.m in your MATLAB installation (or provide a function to override it): : * Start MATLAB as administrator * edit writeXLSFile.m * Search for "autoFit", then comment it out like, * %sheetObj.autoFitColumns(writeRng);
Lucie SOMAGLINO replied on : 5 of 6
Hi Stuart, Thanks a lot for your quick answer. That's works great now! Too bad they didn't make it as an option to the function...

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide