MATLAB: Importing specific cell from excel file using variables.

xlsread

I haven't been able to get around this problem, don't know if it is doable at all. I would appreciate some help
I have a simple problem, at least that's what I think, the code is
A= xlsread('Per.xls', sheet1, 'G2:G2')
Is there a way of retrieving the data by having that "2" in the cell range part be a variable? In other words I want to retrieve a specific cell using input giving by the user, which he/she should be able to change.
Any ideas??

Best Answer

Alejandro - if you have a variable that indicates which cell range you wish to extract data from, then you can easily use this as an input to xlsread. For example,
myRange = 2;
myCells = sprintf('G1:G%d',myRange);
A = xlsread('Per.xls', sheet1, myCells);
Note how we use sprintf to build a string that we can pass to xlsread.