How do I use a for loop with excel

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,

 採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 3 月 11 日

0 投票

height = 5
for z = 1:18
if height == z
s= xlsread('myexcelfile','sheet',sprintf('B%d',z));
end
...
end

2 件のコメント

carl chew
carl chew 2013 年 3 月 11 日
sorry i meant 'Bz:Dz'
how would i write that?
Andrei Bobrov
Andrei Bobrov 2013 年 3 月 11 日
height = 5
for z = 1:18
if height == z
s= xlsread('myexcelfile','sheet',sprintf('B%d:D%d',z,z));
end
...
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by