필터 지우기
필터 지우기

Adding a Column to a Table that

조회 수: 31 (최근 30일)
Omar AlAli
Omar AlAli 2019년 4월 10일
댓글: Partho 2023년 3월 12일
I have a table with 16 columns, I would like to add a 17th column that adds column 11 and 15 together. How would I go about doing that?
Right now I have this but it is not running. The error I get is the following :
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three
or more subscripts) is not supported. Use a row subscript and a variable subscript.
for n=1:25
newtable.NEWVARNAME{n}{:,17}=newtable{n}(:,11)+newtable{n}(:,15);
end

답변 (1개)

Abhishek Singh
Abhishek Singh 2019년 4월 15일
Here is a simple example on how you can do that:
I'll first create a table T.
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(LastName,Age,Smoker,Height,Weight,BloodPressure)
Now to add one more column called Added_height_weight which just adds height and weight columns
and creates a new column, we can do this:
T.Added_height_weight = (T.Age + T.Height)
For more information you can look into:
  댓글 수: 2
Tharindu
Tharindu 2023년 2월 5일
Thanks Abhishek, It worked for me, apparently after 4 years may be. Btw, I am still a new learner of M.
Partho
Partho 2023년 3월 12일
The column will added in the last of the table. How can we add it at the begining?

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by