Export arrays of unknown lengths to next available excel column

조회 수: 2 (최근 30일)
Shana Hartel
Shana Hartel 2015년 8월 11일
댓글: Shana Hartel 2015년 8월 13일
Hello, I am running a loop such that a new array of size (m,1) or possibly (m,2) is generated. Note, m will vary with each loop. I would like matlab to export that array to excel. When this loop runs again to create another array, I want it to export that new array to the next available column in excel. I don't want it to overwrite the last array I exported. If I use xlswrite, how do I vary the range to be a new column with every loop? Or should I be using a different function? Thanks.

답변 (1개)

Varun Bhaskar
Varun Bhaskar 2015년 8월 13일
Hello,
Use the File Exchange submission in the following link to retrieve the Excel column index from the column number in each iteration of the for loop:
Then, you can use the column index to write starting from the first cell in the column using the 'xlswrite' function. It will populate as many rows in each column as the number of data elements to be written.
  댓글 수: 1
Shana Hartel
Shana Hartel 2015년 8월 13일
Thanks Varun! I will have to check this out. I ended up concatenating the cell arrays and exporting that to excel as one output. I just recently learned Matlab can pad cell arrays if you don't preallocate memory. (This was my problem as all my arrays are different sizes and I don't easily know how many rows or columns I need.) Padding the new global array is a bit slower, but it worked. Maybe this Excel Column Conversion will be faster. Thanks again!

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

카테고리

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