How to set just RowNames in a Matrix
조회 수: 46 (최근 30일)
이전 댓글 표시
Hello, Let's assume I got a matrix 3x3
A = [1,2,3;4,5,6;7,8,9];
A.Properties.RowNames = {'row1','row2','row3'};
I got an error Field Assignment to a non-structure array object.
I just wanted to place names in rows and not to create a table. I want to keep as a double if possible.
댓글 수: 0
채택된 답변
Birdman
2018년 3월 7일
편집: Birdman
2018년 3월 7일
Since you do not want to use table, which is really smart to use, I would suggest you to use cell array.
A=mat2cell(A,ones(1,size(A,1)),ones(1,size(A,2)));
A(:,2:end+1)=A(:,1:end);
A(:,1)={'row1','row2','row3'};
and it is easy to reach numeric content of the cell by typing
Anum=cell2mat(A(:,2:end))
추가 답변 (1개)
Stephen23
2018년 3월 7일
편집: Stephen23
2018년 3월 7일
"It creates a table 3x1, and not a table 3x3 that was my goal"
This will create a table of the size that you want.
Using a table will be much simpler than forcing a "header" into a cell array and splitting numeric data into separate cells of a cell array. A table is the correct data class if you want a header.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!