how to append data to existing excel row

Hello,
I have an excel file with string already in it for the first 2 colums and I want to append numeric data after that but I'm having trouble trying to write to the correct row.
Filename Date of addition Number of Cycles Length
# (s)
379Q1172e.v26 10/6/2011 10:58
Below is the code I have written
for i=1:length(cycle)
%extract excel data
[xnum,xtxt,xraw] = xlsread(excel_file);
%find cycle length
comp_cycle=(cycle(i,;2)-cycle(i,1))/100
%find correct cell position to write to
posi = ['C',num2str(length(xraw(:,3)))];
xlswrite(excel_file,{i,comp_cycle},'Data',posi);
end
The problem I'm having is when its read the excel file, the length of the column C returns 3, not 2, so it writes data to the row below it and not the same row as the filename.
Any idea how I can fix this?
Thanks!

3 comentarios

Fangjun Jiang
Fangjun Jiang el 6 de Oct. de 2011
Please re-examine your question. I don't think your mention of row and column is consistent with the data you show.
It might be that the third row of your Excel spreadsheet contains blanks. Check xraw to find it out.
Max Bernstein
Max Bernstein el 6 de Oct. de 2011
Yeah you're right, there is a blank space and shows as []. Is there anyway to overwrite that blank space?
I tried to use posi = ['C',num2str(length(xraw(:,3))-1)];
but it overwrites C2, not C3.
Fangjun Jiang
Fangjun Jiang el 6 de Oct. de 2011
It's easier if you clear your Excel file of those blank cells. Whatever trouble you have, you can put a break point in that line and debug your code. Check the value of posi and you'll know where it starts writing and whether that is what you are expecting.

Iniciar sesión para comentar.

Respuestas (1)

Laura Proctor
Laura Proctor el 6 de Oct. de 2011
Is it just a matter of subtracting one from the length to keep writing on the same row?
posi = ['C',num2str(length(xraw(:,3))-1)];

1 comentario

Max Bernstein
Max Bernstein el 6 de Oct. de 2011
Yeah I tried that too but it wrote to row 2 like this (underscore is just blank space separating cells)
Filename_________Date of addition_____Number of Cycles_______Length
_______________________________________________1____________ 123
379Q1172e.v26_____10/6/2011 10:58
it overwrites the # and (s)

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import from MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Oct. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by