Stuart’s MATLAB Videos

Watch and Learn

Saving Data from MATLAB to Excel Using a Template 8

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.

8 CommentsOldest to Newest

Oren Rosen replied on : 1 of 8
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 8
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 8
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 8
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 8
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...
Ernesto replied on : 7 of 8
Hi Stuart. Thanks for your video. I have a question more. How can I copy only one sheet and paste it into another excel keeping the template?
Stuart McGarrity replied on : 8 of 8
Hi Ernesto, I think that is covered in this video: