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

조회 수: 2 (최근 30일)
MANISH KUMAR
MANISH KUMAR 2017년 3월 25일
답변: dpb 2017년 3월 25일
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!

채택된 답변

dpb
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by