divide every numeric value in table by same number
72 ビュー (過去 30 日間)
古いコメントを表示
HI,
I want to divide every numeric value in my table by the same number but some columns have strings and some have numbers. I want to convert every number in the table from cm to m (but not the strings of course)
thanks
0 件のコメント
採用された回答
Walter Roberson
2023 年 3 月 26 日
divisor = 2;
T = table(["hello"; "orange"], [1;3], [2; 4])
vt = vartype('numeric')
T{:,vt} = T{:,vt} / divisor
3 件のコメント
Siddharth Bhutiya
2023 年 3 月 30 日
Adding on to Walter's answer. Starting 23a there are a lot of standard arithmetic operations that you can directly do on tables to make similar workflows easier. So in 23a you could also use parens indexing instead of brace to get the same results.
T = table(["hello"; "orange"], [1;3], [2; 4]);
vt = vartype("numeric");
T(:,vt) = T(:,vt) ./ 2
In your case since you have a table with mixed types there is a little more work to be done, however, if you only had numerics in you table then it would be very simple now.
T = table([1;3],[2;4]);
T = T./2
You can read more about math operations on tableshere.
その他の回答 (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!