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

조회 수: 1 (최근 30일)
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!

답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 9일
[filename, pathname] = uiputfile('Where do you want it?");
completename = fullfile(pathname, filename);
xlswrite(completename, TheData)

Sachin Ganjare
Sachin Ganjare 2012년 10월 9일
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
Russ
Russ 2012년 10월 11일
편집: Russ 2012년 10월 11일
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 :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by