Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Displaying array in a cell

조회 수: 1 (최근 30일)
Alex
Alex 2013년 4월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
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.

답변 (1개)

Jan
Jan 2013년 4월 29일
Table = cat(1, ...
{'Gray Shade','Digital Units','LE 100% Night','LE 50% Night'}, ...
mat2cell([grayShade digUnits stepsN100L stepsN50L]));
  댓글 수: 2
Alex
Alex 2013년 4월 29일
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 2013년 4월 30일
@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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by