excel data to matlab

Hi all,
Can i ask how to make matlab read data one by one from excel file for each loop.
Say
for num2 = 1:10
A=1+b;
end
for every num2, i want to take data from excel (A1:A10) for example.

 Accepted Answer

for num2 = 1 : 10
thiscell = sprintf('A%d:A%d', num2, num2);
A = xlsread('TheFile.xls', thiscell);
.... do something with A
end
Warning: this will be very inefficient!

3 Comments

Yeah, better to read the whole file into a cell array in a single call to xlsread() and then loop over the array getting the values.
[num, texts, raw] = xlsread(filename);
for row = 1:10
theValue = num(row, 1);
end
zamri
zamri on 7 Jan 2013
Edited: Image Analyst on 7 Jan 2013
great, thanks guys. I try the method from 'Image analyst'.
Be aware that num, texts, and raw do not all necessarily start at the same cell in Excel. They can start at different upper left corners. So num(3,3) could be cell D5, not C3, and texts(3,3) could be E6 and raw(3,3) could come from cell D5 (raw will be the upper left of the combined num and texts).

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!