Using something faster than xlswrite()?

I am using xlswrite to save the outputs each time, so this calls to open excel and its consuming a lot of time. Is there any other faster process for this ?

Réponses (2)

Star Strider
Star Strider le 27 Juin 2016

0 votes

I’m not certain what you’re doing, but I would save the intermediate results to a numeric or cell array, then save the array after the loop in one xlswrite call.

1 commentaire

ck
ck le 27 Juin 2016
Yeah, I used xlswrite after getting the whole output to save it, but even one call is taking aroung 3 sec atleast!

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 27 Juin 2016

0 votes

If by "each time" you mean in a loop, yes, that will take forever, except for more modern versions, like R2015b or later. That's each time you call xlswrite() it has to launch Excel, toss in your data, then shut down Excel. Later versions leave Excel running, which is faster (but which causes other problems by the way). So, what version are you running?
Like Star said, a faster way for all versions is to build your cell array only and THEN write a cell array with a single call to xlswrite().

4 commentaires

ck
ck le 27 Juin 2016
Modifié(e) : ck le 27 Juin 2016
Oh!, I'm using R2013a. I open all columns and rows and write only after the final output is achieved. Say I get the output in 'b' as
4566776666
4545556666
4545555242
2342344433
2423656523
2443344334
so it is a (6x1) matrix then I use xlswrite('myfile.xslx',b) at the end.
So can I know how different would building cell array be than the above method code wise , if possible?
Thank you.
Image Analyst
Image Analyst le 28 Juin 2016
What is b? The 2d 6-by-10 matrix you said was b, or just one column - a 6-by-1 matrix?
If it's the whole 6x10 matrix and you call it just once, there should be no problem If you call xlswrite 10 times, then that will take a very long time.
ck
ck le 28 Juin 2016
b is a 6x1 matrix , so if I call it once it takes around 3 or 3.5 sec.
Image Analyst
Image Analyst le 28 Juin 2016
Modifié(e) : Image Analyst le 28 Juin 2016
So just store b in a 2D array, then call xlswrite
b2d = zeros(6, 10); % Preallocate for speed.
for column = 1 : 10
% Get b
this_b = whatever.....
% Store in 2D array in this column.
b2d(:, column) = this_b;
end
xlswrite(filename, b2d, 'A1');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Tags

Question posée :

ck
le 27 Juin 2016

Modifié(e) :

le 28 Juin 2016

Community Treasure Hunt

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

Start Hunting!

Translated by