フィルターのクリア

Xlswrite in a loop

3 ビュー (過去 30 日間)
Rene
Rene 2013 年 3 月 22 日
Hello,
I want to include xlswrite in a loop. For each pass through the loop, I will write two columns of data to the same Excel sheet. The columns will be continuous. For a few columns I can manually specify the columns to which I write the data. So first pass I will write to cells A1:B12, second pass C1:D12, and so on.
Is there some function in matlab that has the alphabet? I could then call this function and get the letters from the alphabet. I could then generate the ID of the Excel columns automatically.
Thanks so much!

採用された回答

per isakson
per isakson 2013 年 3 月 22 日
>> alphabet = 'A':'Z';
>> alphabet(4)
ans =
D

その他の回答 (1 件)

Cedric
Cedric 2013 年 3 月 22 日
編集済み: Cedric 2013 年 3 月 22 日
It would be more efficient to build an array (or a cell array if you have inhomogeneous/non-numeric content) in the loop, and to export the whole array in one shot at the end. This way, you avoid having to build these complicated column codes. Example:
nBlock = 5 ;
blockSize = [12, 2] ;
content = zeros(blockSize(1), nBlock*blockSize(2)) ;
for k = 1 : nBlock
rowRange = 1 : blockSize(1) ;
colRange = [1,2] + (k-1)*blockSize(2) ;
block = 10*k + rand(blockSize) ; % Some random content.
content(rowRange,colRange) = block ;
end
% One shot output to XLSX file; observe that there is no range information.
xlswrite('myFile.xlsx', content, 'RandomWithOffset') ;

カテゴリ

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