How to write certain data in different sheets of an excel file?
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
dpb
2017-3-25
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!