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

 Accepted Answer

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 Comments

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');
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.
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

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!