Importing specific cell from excel file using variables.

24 views (last 30 days)
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??

Accepted Answer

Geoff Hayes
Geoff Hayes on 16 Feb 2015
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.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!