I have a FOR loop in my code and need to save Result ( vertcat of A and B ) in ONE Excel file in new Row(every columns are same) ,but MATLAB save them (each step) in new Excell file !
for Example:
for i=1:5
A=ones(2,5);
B=zeros(3,5);
xlswrite('testdata.xls',[A;B]);
i=i+1;
end
can you help me

댓글 수: 6

dpb
dpb 2014년 11월 22일
Simplest is to build the entire array in memory and then xlswrite only once after the loop.
Alternatively, you've got to build a dynamic range argument to place the new section where it belongs; what you've told it to do is to write each time starting at cell A1.
Isay
Isay 2014년 11월 22일
편집: Isay 2014년 11월 22일
can you say an example ?
my REAL matrix have 1million Rows and 6000 column! I can't build it in memory!
dpb
dpb 2014년 11월 22일
Excel can't handle that size an array anyway, can it?
Isay
Isay 2014년 11월 22일
i guess yes!
dpb
dpb 2014년 11월 23일
편집: dpb 2014년 11월 23일
Just because the limitations on the number of rows or columns is greater than the limit, that doesn't necessarily mean Excel has any more system memory than does Matlab...I'd guess 48GB is likely going to bring it to its knees as well...or even if not if it actually will try to page, virtual memory paging will kill you. I don't really think Excel is any "more smarter" than Matlab will be on handling this much data. I don't have 64-bit OS so can't really test it, but just sayin'...
Isay
Isay 2014년 11월 24일
please forget 1million Row and other things, and look at my message: i need to Edit " xlswrite('testdata.xls',[A;B]);" to vaertcat A and B UNDER each other in each STEP of Loop. IN ONE EXCEL FILE Just it !
can you Edit for me ?

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2014년 11월 23일

0 개 추천

If you can't fit the 1,000,000 x 6,000 array (48 GB) in memory, then you have to use ActiveX to send it to Excel. See attached demo.

댓글 수: 6

Isay
Isay 2014년 11월 23일
it's faild .
can you send to me A simple code of it ?
Image Analyst
Image Analyst 2014년 11월 23일
How did it fail? What was the error message?
Isay
Isay 2014년 11월 23일
error at line 89 .
please forget 1million Row and other things, and look at my message: i need to Edit " xlswrite('testdata.xls',[A;B]);" to vaertcat A and B UNDER each other in each STEP of Loop. IN ONE EXCEL FILE Just it !
can you Edit for me ?
Try to increase the row each time
numberOfRows = size(A, 1) + size(B, 1);
thisRow = (i-1)*numberOfRows + 1;
cellReference = sprintf('A%d', thisRow);
xlswrite('testdata.xls',[A;B], cellReference);
Isay
Isay 2014년 11월 24일
thanks, But your code Add sheet in each step of (For) loop. I need all of them in ONE Sheet.
Isay, I don't know why it does that - according to the help it should not. But try this - it works:
delete('testdata.xls'); % Delete any prior file.
for i=1:5
A=ones(2,5);
B=zeros(3,5);
numberOfRows = size(A, 1) + size(B, 1);
thisRow = (i-1)*numberOfRows + 1
cellReference = sprintf('A%d:E%d', thisRow, thisRow + numberOfRows-1)
xlswrite('testdata.xls',[A;B], cellReference);
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Moh
Moh 2014년 11월 27일

0 개 추천

try
idx = 0;
for i=1:5
A=ones(2,5);
B=zeros(3,5);
[C,D]=size([A;B]);
xlswrite('testdata.xls',[A;B],1,strcat('A',num2str(1+idx)));
idx = idx+C;
end

카테고리

태그

질문:

2014년 11월 22일

댓글:

2014년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by