MATLAB Answers

0

Determine excel range in writetable function

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.

  0 件のコメント

サインイン to comment.

タグ

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....

  0 件のコメント

サインイン to comment.



Translated by