Multiply column by a number

조회 수: 16 (최근 30일)
Dung Tran
Dung Tran 2023년 5월 23일
댓글: Walter Roberson 2023년 5월 23일
hi , I have a table above, I want to scale up Column 7,8,9 ( Var 7, Var8, Var9) by multiply to 15
somebody please help me to make it. Thank you very much

답변 (2개)

the cyclist
the cyclist 2023년 5월 23일
Here is one way:
varList = ["Var7","Var8","Var9"];
tbl{:,varList} = tbl{:,varList}*15;
  댓글 수: 2
the cyclist
the cyclist 2023년 5월 23일
@Dung Tran, note that @Walter Roberson's and my solutions are largely equivalent; he indexes into the table using the column numbers, and I index into the table using the variable names. It's good to understand both ways.
Walter Roberson
Walter Roberson 2023년 5월 23일
Using the column numbers should be slightly faster -- but if the columns got moved around, then the mapping of which column you wanted to column number could fail, so using the variable names from the columns is more robust when the names are available.

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


Walter Roberson
Walter Roberson 2023년 5월 23일
YourTable{:,[7 8 9]} = YourTable{:, [7 8 9]} * 15;

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by