필터 지우기
필터 지우기

How to assign names for different rows of a vector?

조회 수: 6 (최근 30일)
Zeyad Elsayed
Zeyad Elsayed 2019년 6월 5일
댓글: Adam Danz 2019년 6월 5일
Hello everyone,
I wanted to know if I had a vector created, for example 2 rows by 200 columns, how can I assign a name for the first row of data and then another name for the second row, essentially leaving me with two arrays?
Thanks in advance!
  댓글 수: 1
Adam Danz
Adam Danz 2019년 6월 5일
A vector has only one row or only one column. If your data are 2 x 200, that's a matrix. Matrices do not have a row name property so you can't assign names directly to the matrix. You can have an independent variable that stores the names such as
rownames = {'rowOne'; 'rowTwo'};
or you can put the data into a table. Tables do have a row name property.
data = rand(2,5);
rownames = {'rowOne'; 'rowTwo'};
t = array2table(data,'RowNames',rownames)
Result
t =
2×5 table
data1 data2 data3 data4 data5
________ _______ ________ _______ _______
rowOne 0.039517 0.42084 0.050453 0.86273 0.33966
rowTwo 0.88212 0.63264 0.42274 0.50203 0.43794

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by