Dynamically change column in excel worksheet inside a for loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
Can somebody help me how I can modify/include the follwing code to dynamically write output to Excel file inside a for loop starting from the cell "C9" to advance upto 200 columns?
for i=1:200
Data1{:,i}=prcp(RowID(i,1):RowID(i,2),5);
xlswrite('test.xls',Data1{1,i},'Zone01','??')
end
Thanks in advance,
댓글 수: 0
답변 (1개)
Image Analyst
2014년 9월 25일
Oh my gosh. You definitely don't want to do that, unless you have lots of time to wait or have solid state drives (faster than hard drives by a lot). Launching Excel 200 times, tossing data into it 200 times, saving the file 200 times, and shutting down Excel 200 times will take a very long time. You want to use ActiveX anytime you need to call xlswrite more than about 4 or 5 times. Attached is a demo. With ActiveX, you launch once, toss data in as many times as you want lightning fast, save it once and shut it down once.
댓글 수: 6
Image Analyst
2014년 9월 25일
Is RowID integers, and prcp an array of doubles? And why are you using a cell array for Data1 rather than just a regular old double array? Also, you need to derive the cell reference for Excel. You're stuffing all of these arrays into the same location. Maybe you should just do
for i=1:10
row1 = RowID(i,1);
row2 = RowID(i,2);
Data1 = prcp(row1:row2,5); % Col5 between row1 and row2
cellReference = sprintf('C%d:C%d', row1, row2);
xlswrite1('test.xls', Data1, 'test', cellReference)
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!