How can I use use the index in a FOR loop in a string?
이전 댓글 표시
I need use cycle FOR for String (for Excel write).
For example:
N=10;
for i = 1:N-1
xlswrite('test.xls',F0,brd{i},'A1') %I need change 1 to 2...N
end
How can I do that?
댓글 수: 1
Todd Flanagan
2011년 1월 20일
Hi Pepa. I deleted your "Thanks" answer and added it as a comment to Andreas' answer.
채택된 답변
추가 답변 (3개)
Doug Hull
2011년 1월 20일
I think this is the cleanest way to do this.
N=10;
for i = 1:N-1
colName = ['A' num2str(i)];
xlswrite('test.xls',F0,brd{i}, colName) %I need change 1 to 2...N
end
Walter Roberson
2011년 1월 20일
Or for those who prefer the lower-overhead sprintf:
N=10;
for i = 1:N-1
xlswrite('test.xls',F0,brd{i}, sprintf('A%d',i))
end
댓글 수: 1
Jan
2011년 1월 26일
Thanks Walter! As lean as possible.
Richard de Garis
2011년 1월 26일
0 개 추천
The above solutions are elegantly simple and will serve your current need perfectly. If in the future you require to iterate along Excel columns and/or change the size of the Excel range, I just published a function that will enable you to do that. http://www.mathworks.com/matlabcentral/fileexchange/30180-calculate-excel-range
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!