Since you know the size of the block of data you are reading, you can make your code much more efficient as follows:
firstVals = 1450:9740:89910;
displ = zeros((firstVals(end) - firstVals(1) + 1 + 496), 7);
for ii = firstVals
n = ii + 495;
range = sprintf('B%d:H%d', ii, ii+495);
displ((ii:ii+495)-firstVals(1)+1,:) = xlsread('BrokenDiplacements.xlsx', range);
end
Couple of points:
- I prefer not to use
i
as a variable since it is built in
as sqrt(-1)
- if you later execute code that assumes that to be true, you're in trouble
- I am not assuming that the last value of
ii
is 89910
- by first assigning the value to a vector, then finding the last value in the vector, I sidestep that question
- I assign all space in
iter
at once - otherwise, as it grows, Matlab keeps having to move the array around which can slow things down a lot
- I used
sprintf
to generate the string representing the range - I think it's more readable but it's a question of style
- I assign the return value of
xlsread
directly to a block in displ
that is the right size
I hope this helps.