How do I export a matrix to an Excel file with a custom file name that can be typed in the command window?

Hi everyone.
I am working on a research topic and need to export two matrices into Excel. The matrices can vary in size after a few scripts are run. Ultimately, I need to be able to export the two matrices to two Excel files with the ability for the user to type in any file name he/she wants.
I believe I have to save the file name typed in the command window as a string, then use the xlswrite() command to do it. Not sure where to start. Thanks!

Answers (2)

[filename, pathname] = uiputfile('Where do you want it?");
completename = fullfile(pathname, filename);
xlswrite(completename, TheData)
name_xls1 = input('Enter XLS 1 name:', 's');
name_xls2 = input('Enter XLS 2 name:', 's');
status = xlswrite(name_xls1, MATRIX_DATA1);
status = xlswrite(name_xls2, MATRIX_DATA2);
Hope it helps!!!!

5 Comments

Awesome, this worked well with what I wanted. :)
Any way I can highlight specific columns with different colors and add titles to each column? (All my matrices have 12 columns). Thanks!!
You need to use ActiveX automation interface for doing that, refer below link for further details:
Hope it helps!!!!
Alright. I've checked out ActiveXServer but still can't seem to find out how to do this... here's what I need.
1. Twelve columns with titles in the first 12 cells of row 1, then under each title has the numbers I exported from the Matlab matrices to Excel.
2. The first 5 columns need the cells to be highlighted blue, the next 4 to be in red, and the last 3 in green.
3. One matrix is saved on sheet1, the other on sheet2 in Excel.
Here's the code I have so far:
Excel = actxserver('Excel.Application');
set(Excel, 'Visible', 1);
Workbooks = Excel.Workbooks;
Workbook = invoke(Workbooks, 'Add');
Sheets = Excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 2);
invoke(sheet2, 'Activate');
Activesheet = Excel.Activesheet;
Not much, I know, but I've never used this method before. I used this code from SACHIN's link, and I'm stuck right after loading the matrix. Thanks for the help from both of you so far though :)

Sign in to comment.

Asked:

on 9 Oct 2012

Community Treasure Hunt

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

Start Hunting!