Displaying array in a cell
조회 수: 1 (최근 30일)
이전 댓글 표시
I have described three double arrays and I am trying to create a table that I can then write to excel using xlswrite. I define my table, but I want the double arrays to show up in the table as columns of data when I write to excel. here is my code
Table = {'GrayShade', 'Digital Units', 'LE Night 50%'; grayShade digUnits stepsN50L};
xlswrite('Gamma Stability.xlsx',Table,'Gray Shade Table','B2');
assume grayShade, digUnits, and stepsN50L are all good double arrays with data in them...because they are. No problem there. When I use the above code, the cell table only has the column titles in it and instead of having a column of data, a single cell underneath each title says double and it does not columnate the data. How do I do this?
답변 (1개)
Image Analyst
2013년 4월 25일
You need to put each number from the array into its own cell. So if those arrays are 10 rows by 5 columns, you'll need a 11 row by 15 column cell array. Put the strings into the first row. If you want an empty cell, you still need to put in []. Then loop over the arrays putting one number into each cell until you have all cells from row 2 down through row 11 filled in with your arrays. Then write that cell to Excel. If you don't understand, give your array dimensions and I could write up a little demo.
댓글 수: 2
Cedric
2013년 4월 26일
편집: Cedric
2013년 4월 26일
Image Analyst's answer suggests the following:
header = {'GrayShade', 'Digital Units', 'LE Night 50%'} ;
data = mat2cell([grayShade, digUnits, stepsN50L]) ;
Table = [header; data] ;
This assumes that all your numeric arrays are column vectors. If you don't want to care about their shape, you can replace the second line with:
data = mat2cell([grayShade(:), digUnits(:), stepsN50L(:)]) ;
There is no FOR loop; MAT2CELL does the trick. If you look at data, you'll see that it is a cell array, and that each cell contains a single number. In your first attempt, you were passing a 2 x 3 cell array to XLSWRITE, which was trying to store the content of e.g. cell Table(2,1) [which was the whole array grayShade] into a single Excel cell.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!