more efficient code while using xlswrite and xlsread
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello!
I use the code below,which works fine, but i believe there is a more sufficient way to write the code.
function Copydata(excelfile1,excelfile2,n)
for i=1:n*3
T(:,i)=xlsread(excelfile1,i,'A43:A51');
end
i=1;
for j=1:n
xlswrite(excelfile2,T(:,i),j,'O17:O25')
i=i+1;
xlswrite(excelfile2,T(:,i),j,'P17:P25')
i=i+1;
xlswrite(excelfile2,T(:,i),j,'Q17:Q25')
i=i+1;
end
i tried readtable() and writetable() but they are a bit slower!
Any idea how to rewrite the code either using the same commands(xlswrite,xlsread), or using something else like ActiveX?
Thank you in advance!
P.S: I am using Matalab R2014a
댓글 수: 0
채택된 답변
Jon
2019년 9월 23일
편집: Jon
2019년 9월 23일
Can you use just one call as follows
xlswrite(excelfile2,T(:,1:3),j,'O17:Q25')
or assuming that that T has only 3 columns
xlswrite(excelfile2,T,j,'O17:Q25')
p.s. In your question title, I think you mean to say more efficient rather than more sufficient
댓글 수: 4
Jon
2019년 9월 24일
편집: Jon
2019년 9월 24일
Are you sure you have the range as 'O17:Q25' and not 'O17:O25' ? O and Q look very similar could be an easy one to overlook.
When I do a simple test of this approach it seems to work fine.
For example if I type on the command line
T = randn(9,10),i=4,j=3,xlswrite('junk.xlsx',T(:,i:i+2),j,'O17:Q25')
Note you may have to scroll the window to the right to see the O,P,Q columns in the screen shot. Seems like it works here. Is this exactly what you are doing within your code?
P.S. Please know that I was just trying to clarify on the sufficient/efficient wording, I know English can be really difficult and I admire your efforts to master it.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 ActiveX에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!