I have few excel program that I needed to be read by MATLAB. Now I want to enter the file name as an input. How do I make Matlab read that input file name?

조회 수: 1 (최근 30일)
I have an excel program which contains different sheets and I need Matlab to read the data in each sheet one by one. I am required to put the file name (excel file) as an input and need Matlab to read the input variable. How do I do it?

채택된 답변

Konstantinos Sofos
Konstantinos Sofos 2015년 10월 31일
Hi,
xlsfinfo will get you a list of sheet names into your Excel file.
[~,sheets] = xlsfinfo(filename);
Then you can use xlsread to read data from each specific sheet.
A more elegant way (that I suggest) is to learn how to use ActiveX to parse data from your Excel e.g.
filename = 'C:\SomeExcelFile.xls';
% Open Excel Automation server
Excel = actxserver('Excel.Application');
% Make Excel visible
Excel.Visible=1;
% Open Excel file
Workbook = Excel.Workbooks.Open(filename);
% Get the list of sheets in the workbook
Sheets = Excel.ActiveWorkbook.Sheets;
% Save the file
Workbook.Save();
% Quit Excel, remove the COM server and delete the related objects
Excel.Quit();
Excel.delete();
  댓글 수: 1
SOHAM BANERJEE
SOHAM BANERJEE 2015년 10월 31일
I was using A=xlsread('NSKapkot.xlsx','20080819','B3561:B3961') command. But I want to input all those within the inverted comma in a variable. Like while running the program it would ask me the name of the file, sheet no , column & row and after providing those it will be able to read the file accordingly.

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

추가 답변 (0개)

카테고리

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