# How to save each iteration of a loop into the same sheet of an Excel spreadsheet?

27 visualizaciones (últimos 30 días)
Alberto el 13 de Oct. de 2015
Comentada: Rehannara Beegum Thajudeen el 4 de Oct. de 2021
Hello, I'm still relatively new to MATLAB.
I am trying to save data into an Excel Sheet, I have successfully managed to save single iteration of the loop in a given sheet. I have managed to save each iteration in a new sheet(as shown below in the code). However, I am interested in saving each iteration in the same sheet but within the following row of the Excel sheet. For example, heading save to row 1. Iteration 1 save to row 2, Iteration 2 save to row 3 and so on.
I understand I can specify the range ('Range','A1') for example to save to row 1. However, I do not know how to make the Range vary in relation to the length of START. What I mean is, if it is Iteration 2 how can I specify 'A3". The end purpose of the code is to generate large amounts of data.
filename = 'Test.xlsx';
z = 1;
START = [0.2:0.1:0.9];
for i = 1:length(START);
start = START(i);
global start;
run 'Improved.' %m.file named 'Improved.m'
Table_1 = table(z,n,A,B,C,D); %variables "z,n,A,B,C,D" are generated within Improved.m
z = z+1;
sheet = z;
writetable(Table_1,filename,'Sheet',z,'Range','A1')
end
Thank you
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Andy el 13 de Oct. de 2015
xlFilename = 'c:\data\filename.xls';
xlRange = strcat('A',int2str(i));
xlswrite(xlFilename,yourdata,'YourXLSheetName',xlRange);
If your data is a vector this will write each number in cells across the spreadsheet starting in the cell specified by xlRange.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Rehannara Beegum Thajudeen el 4 de Oct. de 2021
Thank you for sharing this information, in my code it really worked.

Iniciar sesión para comentar.

### Más respuestas (1)

Eng. Fredius Magige el 13 de Oct. de 2015
Hi Iam not competent with the rest, except (note that, if table(table(z,n,A,B,C,D)) is common in coding or your own code), you have:
start(i,1)=START(i); %etc
which might assist in row and column arrangment
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Spreadsheets en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by