Export cell array into Excel, with each column in a separate Excel Sheet
조회 수: 10 (최근 30일)
이전 댓글 표시
I have a 87x46 cell array called "ExpSimple". Within this cell array, the size of each cell is: 1 row by k columns, where k changes (as you can see in the attached screenshot).
I would like to export this cell array in Excel in the following manner:
Each Excel sheet must have one column of the array "ExpSimple". Hence, the Excel file must have 46 sheets. Then, within each Excel sheet, the rows must have the content of each cell. At the end, each of the 46 Excel sheets will have 87 rows. How can I do this? Note that some columns are empty (for example, row 8 column 10). Also, the cell data is text or strings, not numerical values. I'm using Matlab version R2017b
Thanks,
JJ
댓글 수: 0
답변 (1개)
Raghava S N
2024년 11월 20일 4:11
As each column of the cell array should be written into a different sheet of the same Excel file, the “xlswrite” function can employed to achieve this export. I have detailed a workflow below, which can be followed to execute this task.
First, iterate through each column of the “ExpSimple” cell array, treating each column as a separate sheet in the Excel file. Then, extract the data from each column. Loop through the extracted data and if an empty cell is found, over-write it with an empty string. This ensures that the Excel file accurately reflects the content of the “ExpSimple” cell array.
Create a new sheet and write the extracted data into the corresponding rows of that sheet. This can be done by passing a string as the name of the sheet for the “sheet” parameter in the “xlswrite” function, along with the extracted data for the “Input matrix” parameter and the name of the Excel file for the “filename” parameter. Repeat this process for each column in the “ExpSimple” cell array.
The “xlswrite” function is particularly useful because it can handle both numerical and textual data, and it allows for writing data into specified sheets within an Excel file. For more information about the “xlswrite” function, execute this command in the MATLAB command window-
web(fullfile(docroot, 'matlab/ref/xlswrite.html'))
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!