|
|
Re: How to Select Entire Row From Excel File Uisng Prompt?
Posted:
Nov 18, 2012 7:07 PM
|
|
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'; answer=inputdlg(prompt,title); 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" <phil@goddardconsulting.ca> wrote in message <k8b90m$4g8$1@newscl01ah.mathworks.com>... > 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.
|
|