How to use XLSWRITE when XLRANGE depends on a cell

1 view (last 30 days)
Hi,
I run a Matlab code that extracts data from an Excel file. My data is sorted by column (e.g. dates from 2000 to 2012 in column A, Volatility corresponding to each date in column B...). In Excel, I find the row with the row function which I store in a cell. I would like to export my answer (I have 2 answers) to another Excel file to a specific that specific row each time.
For example, if my volatility is in row 7165, I would like to write my answers to cell D7165:E7165 (xlswrite('file',answers,'Sheet2',D1:E1)) But when I re-run the code with volatility row 7166, I want the answer to write in cell D7166:E7166. I would like the row to change automatically without me changing manually it everytime.
Thank you very much for your help,

Accepted Answer

Image Analyst
Image Analyst on 14 Dec 2012
Read your data. Figure out the row number - I'm not sure how you get that, but it seems like you know how to get it. Then use sprintf() to create a range, and write data back out.
range = sprintf('D%d:E%d', rowNumber); % e.g. rowNumber = 7165.
xlswrite(fullFileName, answers, 'Sheet2', range); % Answers is your data array.
  5 Comments
Beverly
Beverly on 13 Mar 2014
Do you know how to change the column similarly to the row?
Image Analyst
Image Analyst on 13 Mar 2014
What form is your column in? Is it in a variable? A number? A letter? Or do you just want to hard code it in?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!