How to write certain data in different sheets of an excel file?

2 visualizaciones (últimos 30 días)
MANISH KUMAR
MANISH KUMAR el 25 de Mzo. de 2017
Respondida: dpb el 25 de Mzo. de 2017
I want to save the data generated for certain variables to multiple sheets of different excel files.
For example, I want to save variables [N, d, K, T, A and R] to different sheets of an excel file named ‘LCD-X-i’.
Now, for different values of ‘X’ and ‘i’ a different excel file is created.
For example
For X = 3 and i = 1 the file name should be LCD-3-1.
Similarly as the loop forwards the others files will be like
LCD-3-2
LCD-3-3
.
.
LCD-4-1
LCD-4-2
.
.
And so on …
I am using the following code for this:
for i = 1:5
for X = 3:7
N = X;
d = randi([1,3] , 1, N);
K = randi([1,2]);
T = fix((randi([8,10])/10) * sum(d));
A = randi([10,15] , K,N);
R = 4*max(max(A));
xlswrite('LCD-(X)-(i).xls' , [N d K T A R] , [1:6]);
end
end
Note: [1:6] are the sheet numbers for each variable.
Please help.
Thanks in anticipation!

Respuesta aceptada

dpb
dpb el 25 de Mzo. de 2017
See the FAQ 'Process sequence of files'. While written specifically for the reading files, creating filenames from variables is equally as appropriate for writing and for building strings for spreadsheet names or regions.
Give it a go; num2str is quite handy here altho not really any different than sprintf

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by