How do I write a combined cell array/struct to excel in a loop, moving one column over for each iteration?

1 view (last 30 days)
My variable Cyc(iiFile).Dch{n} encompasses the file number iiFile and the cycle of discharge (n). For simplicity, I called n = 1. I want to write starting in column B2 for iiFile = 1 and move to C2 for iiFile = 2, etc. Eventually, I will want to add in the 2nd discharge cycle for n = 2 beside each n=1 column vector. The code below works, but keeps overwriting the column vector under cell index B2.
for t = 1:iiFile % for n = 1 to numel( n=1; xlswrite('Test_Data.xlsx',Cyc(iiFile).Dch{n},'Dch','B2') end

Accepted Answer

Mischa Kim
Mischa Kim on 13 Mar 2014
Edited: Mischa Kim on 13 Mar 2014
Beverly, use strcat to modify the cell name you need to write to:
C(1).D = 'b'; % some random data
C(2).D = 'c';
C(3).D = 'd';
for ii = 1:3
sheet = 1;
range = strcat(char(65 + ii),'2'); % create excel cell name
xlswrite('Test_Data.xlsx',C(ii).D,sheet,range)
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!