How to specifiy section of Array to write to certain cells in Excel file

I want to write a certain section of array to certain cells in excel sheet.
I tried the following to no avail
xlswrite('MIauto', C(A1:K19), Capital, 'C274:M290');
'C' is my array but I want write a section of it to excel sheet.
Is there some way of doing this? thanks P

 採用された回答

dpb
dpb 2015 年 8 月 18 日
Sure, but to address array elements in Matlab you don't use Excel spreadsheet notation; simply the range expression you want. Presuming the 'A1,K19' is indicative of the size and location desired for 'C' then
xlswrite('MIauto', C(1:19,1:11)); % write a subsection of C to Excel
It is possible to make some use of the Excel addressing style if that's the actual form in which you know intuitively the size desired instead of numeric...
xlswrite('MIauto', C(1:19,1:'A'-'K'+1));
Matlab does the conversion and arithmetic automagically, you need the "+1" to account for the number of elements inclusive in the range.

3 件のコメント

Patrick Tierney
Patrick Tierney 2015 年 8 月 20 日
編集済み: Patrick Tierney 2015 年 8 月 20 日
Ok thanks I get the array but I still want to allocate this a specific section of the excel sheet 'Capital'. I tried the following but no joy. Any thoughts? Cheers
xlswrite('MIauto', C(1:7,1:11),Capital,'C14:M21');
dpb
dpb 2015 年 8 月 20 日
Unless Capital is a variable containing the string 'Capital' or the correct numeric order number of the sheet in the workbook, it's bound to fail...I presume you meant to write
xlswrite('MIauto', C(1:7,1:11),'Capital','C14:M21')
Plus, the range 14:21 includes 8, not 7 rows...not sure whether xlswrite will care about that mismatch or not as the target is larger than the subject array.
Patrick Tierney
Patrick Tierney 2015 年 8 月 20 日
ok got it working. I needed single quoatations on the worksheet and file must be closed. Something like this xlswrite('blankMI.xls', C(1:6,1:11),'Capital', 'C15');
cheers P

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Data Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by