xlswrite to specific cells

I have 3 variables that I would like to write to excel. I want them written to specific cells, like variable 'a' goes to cell A1, variable 'b' goes to cell C3 and so on. I use this code:
filenametest = 'writetest';
xlswrite(filenametest, [a b c],'Sheet1',['A1' 'C3' 'B9'])
This does not work and I can't find any solutions on any help files.
Can you help?
Thanks..

3 件のコメント

Adam
Adam 2017 年 8 月 30 日
Looks like you'd have to just do 3 separate calls to xlswrite. The xlRange parameter clearly states it must be a rectangular range so you can't just put random cells in.
Soren Hansen
Soren Hansen 2017 年 8 月 30 日
OK, thanks. This is what I have done so far, but i hoped that I could expedite the process by doing it in "one call".
Jan
Jan 2017 年 8 月 30 日
Note that ['A1' 'C3' 'B9'] is the same as 'A1C3B9'. Whenever you write "does not work" in the forum, care for explaining, what happens instead: Do you get an error message or does the result differ from your expectations. Usually this explanation contains the main part of the solution already.

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

回答 (3 件)

Jan
Jan 2017 年 8 月 30 日

0 投票

As Adam has suggested
xlswrite(filenametest, a, 'Sheet1', 'A1')
xlswrite(filenametest, b, 'Sheet1', 'C3')
xlswrite(filenametest, c, 'Sheet1', 'B9')
KL
KL 2017 年 8 月 30 日

0 投票

If you put all the variables in one cell array, then maybe
varCell = {a,b,c};
xlCell = {'A1','B3','C7'};
cellfun(@(v,c) xlswrite(filenametest,v,1,c),varCell,xlCell)
deepika Sridhar
deepika Sridhar 2018 年 5 月 9 日

0 投票

what is c what is v

1 件のコメント

Walter Roberson
Walter Roberson 2018 年 5 月 9 日
In KL's answer, v and c are the dummy parameter names for the anonymous function. KL appears to have used v to stand for variable, and c to stand for cell reference.

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

タグ

質問済み:

2017 年 8 月 30 日

コメント済み:

2018 年 5 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by