Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Displaying array in a cell

3 visualizzazioni (ultimi 30 giorni)
Alex
Alex il 29 Apr 2013
Chiuso: MATLAB Answer Bot il 20 Ago 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.

Risposte (1)

Jan
Jan il 29 Apr 2013
Table = cat(1, ...
{'Gray Shade','Digital Units','LE 100% Night','LE 50% Night'}, ...
mat2cell([grayShade digUnits stepsN100L stepsN50L]));
  2 Commenti
Alex
Alex il 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 il 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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by