How can I avoid an "internal exception" xlswrite error?

I am currently attempting to write data from a loop into an excel file that already contains data. However, I receive an internal exception error when I attempt to do this (even if I just use a different sheet). When I try to write the data into an empty excel file, I don't have this issue. Any idea how to avoid this error?
%Data Input
filename = 'RocketData.xlsx';
num = xlsread(filename);
%Data Definitions
deltat = num(1,1);
printing = num(2,1);
Vbottle = .002;
f = num(4,1);
Dn = num(5,1)*.0254;
Anozzle = num(6,1)*.00064516;
Aprojected = num(7,1)*.00064516;
mpayload = num(8,1)*.001;
mrocket = num(9,1)*.001;
Pairini = num(10,1)*6894.752728;
Cd = num(11,1);
C = num(12,1);
Li = num(13,1)*.0254;
g = 9.81;
c = 343;
Mair = .029;
gamma = num(17,1);
Patm = num(18,1)*101.325;
rhowater = 1000;
Tamb = num(20,1) + 273.15;
R = 8.314;
%Phase 1 Initial Calculated Values
T = Tamb;
rhoatm = (Mair*Pairini)/(R*T);
rhoair = (Mair*Pairini)/(R*T);
Vairini = (1-f)*Vbottle;
mairini = Pairini*Vairini;
mwaterini = f*Vbottle*rhowater;
mtotal = mrocket + mpayload + mwaterini + Mair;
t = 0;
x = 0;
vrocket = 0;
Vini = (1-f)*Vbottle;
Tini = Tamb;
%Phase 1 Data Initial Calculations
mwater = mwaterini;
counter = 25;
kk = 0;
while mwater > 0
kk = kk + 1
Vair = Vbottle - (mwater/rhowater);
Pair = (mairini * R * T)/(Mair * Vair);
mdotwater = .01;
mwater = mwater - (mdotwater * deltat);
mtotal = mrocket + mwater + mairini;
vwater = C*(2*(Pair-Patm)/(rhowater))^(.5);
Fthrust = mdotwater * vwater;
Fgravity = (mtotal * 9.81);
Fdrag = .01
Fnet = Fthrust - Fgravity - Fdrag;
arocket = (Fnet)/(mtotal);
deltat = 1e-4*kk
if (mod(deltat,.01)==0)
counter = counter + 1;
xlswrite('RocketPrac.xlsx',Vair,1,['B',num2str(counter)]);
xlswrite('RocketPrac.xlsx',Pair,1,['C',num2str(counter)]);
xlswrite('RocketPrac.xlsx',mwater,1,['D',num2str(counter)]);
xlswrite('RocketPrac.xlsx',mtotal,1,['E',num2str(counter)]);
xlswrite('RocketPrac.xlsx',vwater,1,['F',num2str(counter)]);
xlswrite('RocketPrac.xlsx',Fthrust,1,['G',num2str(counter)]);
xlswrite('RocketPrac.xlsx',Fgravity,1,['H',num2str(counter)]);
xlswrite('RocketPrac.xlsx',Fdrag,1,['I',num2str(counter)]);
xlswrite('RocketPrac.xlsx',Fnet,1,['J',num2str(counter)]);
xlswrite('RocketPrac.xlsx',arocket,1,['K',num2str(counter)]);
xlswrite('RocketPrac.xlsx',deltat,1,['A',num2str(counter)]);
end
end
Here is the code I used. Make sure you also use the excel file that is attached (the program reads the data from the excel file).

3 comentarios

Shouldn't get an internal error no matter what--report to Mathworks bug.
Looks ok to me; looks like if it's a real problem you could demonstrate it simply with a single call w/o anything else--the Office installed here isn't recent enough to handle the .xlsx format but
>> Vair=pi;counter=1; xlswrite('RocketPrac.xls',Vair,1,['B',num2str(counter)])
>> xlsread('RocketPrac.xls')
ans =
3.1416
>> Vair=sqrt(pi);counter=1; xlswrite('RocketPrac.xls',Vair,1,['B',num2str(counter)])
>> xlsread('RocketPrac.xls')
ans =
1.7725
>>
seems to work fine whether there's data in the file or not (first time created it; second rewrote the value). Might just for grins try the older format .xls and see if that helps any there or not.
Matthew
Matthew el 20 de Abr. de 2014
I recreated the excel file I was using as a .xls files and the program worked beautifully on two consecutive occasions. When I changed the file to a .xlsx file again, "Error: The server threw an exception."
#$#% you too Matlab.
Thanks for the help!
dpb
dpb el 20 de Abr. de 2014
Well, as suggested, submit a bug report to TMW

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 20 de Abr. de 2014
You certainly certainly don't want to call xlswrite() that many times! Do you know it has to launch Excel, write out that one number, and shutdown Excel each time. It will take forever. You'd be better off using ActiveX to do it. Just open once using ActiveX, toss all your data in (virtually instantly), then close it once. It will be much, much, MUCH faster. I'm talking seconds instead of minutes or hours. See attached demo.
Or even better, try creating a table and use writetable() to write out your xlsx file. See table in the help (requires R2013b or later).

Etiquetas

Preguntada:

el 20 de Abr. de 2014

Respondida:

el 20 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by