writecell produces two cells when Range is a sigle cell

I am writing a since cell varialbe to an excel spreadsheet and the desired range changes each time. I decode the range as a selected Column (i.e., 'AX') concatenated to the row number i'm writing. Each time, the writecell produces the cell in the desired column and row, but also in the just previous column and row. The variable I'm writing is a single cell element. My code is:
Clm = cell2mat(ColmnName(jj));
Rng = [Clm num2str(irow)];
writecell(Cost,fnameout,'Sheet',1,'Range',Rng);
where, Clm = 'AE', irow = 31, Cost is a cell variable that changes each call, in this case Cost = 1×1 cell array / {[255.7800]}
writecell wrote to column AD and AE in row 31.

 Respuesta aceptada

Stephen23
Stephen23 el 19 de Jul. de 2026
Editada: Stephen23 el 19 de Jul. de 2026
Try this:
Rng = sprintf('%1$s%2$d:%1$s%2$d', ColmnName{jj}, irow);
writecell(Cost, fnameout, 'Sheet', 1, 'Range', Rng);
Learn how to use curly brace indexing, rather than relying on awkward CELL2MAT:

2 comentarios

Mike
Mike el 19 de Jul. de 2026
Yes, that did work.. Thank you.
Mike S
@Mike: i hope that it helped. To show your appreciation please remember to click the accept button.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2024a

Preguntada:

el 19 de Jul. de 2026

Comentada:

el 20 de Jul. de 2026

Community Treasure Hunt

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

Start Hunting!

Translated by