The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to Select Entire Row From Excel File Uisng Prompt?
Replies: 11   Last Post: Nov 23, 2012 5:52 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 150
Registered: 2/11/08
Re: How to Select Entire Row From Excel File Uisng Prompt?
Posted: Nov 18, 2012 7:07 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Thanks for the help Phil, but that didn't work for me. I made some changes to the code, and I'm working with this now (code below). However, it?s definitely NOT dynamic.

excelObj = actxserver ('Excel.Application');
% Full path to your file required
fileObj = excelObj.Workbooks.Open('C:\Program Files\MATLAB\R2012a\StockSymbols.xls');
sheetObj = excelObj.Worksheets.get('Item', 'Symbols');
filename = 'C:\Program Files\MATLAB\R2012a\StockSymbols.xls';

% Row end, appears to work for rectangular data in sheet.
rowEnd = sheetObj.Range('A1').End('xlDown').Row
% Column end for first row
colEnd = sheetObj.Range('A1').End('xlToRight').Column

prompt={'Enter an Excel Row:'};
title='Enter an Excel Row';

sheet = 'Symbols';
xlRange = 'A16:S16';

subsetA = xlsread(filename, sheet, xlRange);

Basically, what I?m trying to do is enter a value into an InputBox and pass that into ColumA of the Excel file, and copy the data from that specific row (xlRange) into a Matlab variable named subsetA. So, it?s almost like a Vlookup from Matlab into Excel, and then copy the range (the entire row) into a Matlab variable. All values in ColumnA are dates (this is what I pass to the InputBox). I want to import the different stock prices.

"Phil Goddard" <> wrote in message <k8b90m$4g8$>...
> You could spend time digging into the file to see how many columns of the specified row are actually used and then just extract those cells, but it may be just as quick to use a sledge hammer approach
> try
> % Reading 2007 and 2010 files
> row = xlsread('myfile.xls',sprintf('A%d:XFD%d',rowNumber));
> catch ME %#ok
> try
> % read 2003 files
> row = xlsread('myfile.xls',sprintf('A%d:IV%d',rowNumber));
> catch ME
> rethrow(ME);
> end
> end
> % Strip nans from the result
> % (This will strip all nans not just those at the end of the row.)
> data = row(~isnan(row));
> Phil.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.