Multiply column by a number
显示 更早的评论

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
2023-5-23
Here is one way:
varList = ["Var7","Var8","Var9"];
tbl{:,varList} = tbl{:,varList}*15;
2 个评论
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
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
2023-5-23
YourTable{:,[7 8 9]} = YourTable{:, [7 8 9]} * 15;
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!