How do I read data from an Excel Spreadsheet using the Automation client support in MATLAB?
18 views (last 30 days)
Show older comments
I would like to use the Automation client (COM/ActiveX) support in MATLAB to read data from an MS Excel Spreadsheet.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The following sample code illustrates how you can read data from an Excel File using the COM Automation support in MATLAB:
hExcel = actxserver('excel.application');
hExcel.Workbooks.Open('testxlsread.xls');
%BtchData is the name of the sheet:
data = hExcel.Worksheets.Item('BtchData').UsedRange.Value;
hExcel.Quit;
delete(hExcel)
The variable "data" will now store all the data that's read from Excel as a cell array.
You can then parse through to read the numeric and text data from the cell array:
for n = 1:r
for m = 1:c,
if ischar(data{n,m})
A(n,m) = NaN;
else A(n,m) = data{n,m};
data{n,m} = [];
end
end
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!