more efficient code while using xlswrite and xlsread
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Jon
am 23 Sep. 2019
Bearbeitet: Jon
am 23 Sep. 2019
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 Kommentare
Jon
am 24 Sep. 2019
Bearbeitet: Jon
am 24 Sep. 2019
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu ActiveX finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!