Displaying array in a cell

3 views (last 30 days)
Alex
Alex on 25 Apr 2013
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 Comment
Alex
Alex on 25 Apr 2013
Well I meant for it to say "17x1" everywhere that it currently says double

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Apr 2013
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 Comments
Alex
Alex on 25 Apr 2013
I do not understand entirely...all the arrays are 17 rows by 1 column. Are you saying I have to write a for loop to write in every individual entry from the array into the cell one by one?
Cedric
Cedric on 26 Apr 2013
Edited: Cedric on 26 Apr 2013
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!