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!