Info

This question is closed. Reopen it to edit or answer.

Displaying array in a cell

2 views (last 30 days)
Alex
Alex on 29 Apr 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
I am trying to copy an already existing column vector into a cell array and have it display as a column when I import in excel using xlswrite. Here is my code.
Table={'Gray Shade','Digital Units','LE 100% Night','LE 50% Night'; grayShade digUnits stepsN100L stepsN50L);
xlswrite('Gamma Stability.xlsx', Table, 'Gray Shade Table', 'B2');
What I am trying to get is for the first four entries in Table to be the column headers and for the last four to be the data after the columns. The variables grayShade, digUnits, stepsN100L, and stepsN50L are all 17 rows by 1 column in size. When I execute this command, it writes Table, but it comes out as a 2x4 cell array with the column headers in the first row, and every cell in the second row saying '17x1 double'. Not sure how to make it write in the actual data. I would like my cell array to be an 18x4 when I am done.

Answers (1)

Jan
Jan on 29 Apr 2013
Table = cat(1, ...
{'Gray Shade','Digital Units','LE 100% Night','LE 50% Night'}, ...
mat2cell([grayShade digUnits stepsN100L stepsN50L]));
  2 Comments
Alex
Alex on 29 Apr 2013
I typed in your code, both with the ... and without and I got this:
Warning: Single input behavior is obsolete and will be removed in a future release of MATLAB.
Use C={X} instead.
> In mat2cell at 53
Error using cat
Dimensions of matrices being concatenated are not consistent.
I double checked the matrices and they are definitely the same dimensions. Any ideas?
Jan
Jan on 30 Apr 2013
@Alex: And then you started to analyse what's going on, correctly? Or are you waiting for me?
I cannot know the dimensions of grayShade etc., therefore I cannot guess, how this command have to look like exactly. But you have all information about this, to I encourage you to try to solve it. Perhaps you want:
mat2cell([grayShade(:), digUnits(:), stepsN100L(:), stepsN50L(:)])
You cannot simply omit the "...", which are the line continuation makr in Matlab.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!