Determine excel range in writetable function

24 ビュー (過去 30 日間)
Danielle Leblance
Danielle Leblance 2017 年 2 月 5 日
回答済み: Image Analyst 2017 年 2 月 5 日
I have multiple tables t1 t2...t45 and i want to write them on one sheet in excel using write table. All of them have the same number of rows but different number of columns. for example t1=6000x4 whereas t2=6000x3.How can I write these tables in consecutive columns in excel?
In other words, t1 range is A1:D6000 but I want t2 to be E1:G6000. So, I can can solve it using:
writetable(t1,'myfile.xlsx','Sheet',1,'Range','A1:D6000')
writetable(t2,'myfile.xlsx','Sheet',1,'Range','E1:G6000')
but how can i generate the range automatically with the 45 tables. some tables have 78 columns which makes it very hard to determine the range manually.

回答 (1 件)

Image Analyst
Image Analyst 2017 年 2 月 5 日
Use ExcelCol at http://www.mathworks.com/matlabcentral/fileexchange/27182-excel-column-conversion to convert column number to a letter or pair of letters. Then do
column = 1;
columnLetters = char(ExcelCol(column));
% Convert to Excel A1 format
cellReference = sprintf('%s1', columnLetters);
% Write the table
writetable(t1,'myfile.xlsx','Sheet',1,'Range', cellReference)
% Go to next column, skipping a column.
column = column + size(t1, 2); % Change the variable name inside size().
% Should be the prior variable, not the current one you're about to write.
cellReference = sprintf('%s1', columnLetters);
writetable(t2,'myfile.xlsx','Sheet',1,'Range',cellReference)
% Go to next column, skipping a column.
column = column + size(t2, 2); % Change the variable name inside size().
% Should be the prior variable, not the current one you're about to write.
cellReference = sprintf('%s1', columnLetters);
writetable(t3,'myfile.xlsx','Sheet',1,'Range',cellReference)
% And so on....

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by