Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How do I use a for loop with excel

Asked by carl chew on 11 Mar 2013

I am making a for loop that draws in excel and I cannot get the right syntax to change the row given the iteration constant "z". My for loop works when I have for example: 'B5:D5', but when i want to incorporate the iteration constant it does not work. Help please

height = 5

for z = 1:18

    if height == z
    s= xlsread('myexcelfile','sheet','Bz:Bz')

....the rest of the loop works fine,

0 Comments

carl chew

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 11 Mar 2013
Accepted answer
height = 5
for z = 1:18
    if height == z
        s= xlsread('myexcelfile','sheet',sprintf('B%d',z));
    end
    ...
end

2 Comments

carl chew on 11 Mar 2013

sorry i meant 'Bz:Dz'

how would i write that?

Andrei Bobrov on 11 Mar 2013
height = 5
for z = 1:18
    if height == z
        s= xlsread('myexcelfile','sheet',sprintf('B%d:D%d',z,z));
    end
    ...
end
Andrei Bobrov

Contact us