How can I use sprintf and xlswrite to insert data into a specific cell?

Suppose I have :
start = 1
finish = 10
for i = start:finish
my_cell = sprintf( 'K%s',num2str(i));
xlswrite('exceldoc',filename(i),'data',my_cell);
end
I want to insert the first data point at K2 in excel, but I cannot because 'K%s' begins inserting at K1. Subsequently, if I were to use 'K02%s' it would begin at cell K21.
Any help would be fantastic

2 件のコメント

Mick Fic
Mick Fic 2015 年 10 月 30 日
Thanks, it works perfectly.
dpb
dpb 2015 年 10 月 30 日
Depending on what the data are you're actually writing, the loop may not be needed at all; can't tell as you don't give enough info...

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

 採用された回答

dpb
dpb 2015 年 10 月 29 日
start = 1;
...
for i = start:finish
my_cell = sprintf('K%d',i);
...
The superfluous num2str aside (as shown, just use the proper numeric output field descriptor), if you want to target starting at K2 then just for the looping indices by compensating in the conversion statement--
my_cell = sprintf('K%d',i+1);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Use COM Objects in MATLAB についてさらに検索

質問済み:

2015 年 10 月 29 日

コメント済み:

dpb
2015 年 10 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by