How do we do operations directly on table elements in matlab?

14 ビュー (過去 30 日間)
D_coder
D_coder 2020 年 7 月 2 日
コメント済み: Walter Roberson 2020 年 7 月 2 日
I am thinking of doing min max normalization of my data where if x is vector the procedure is as follows x = (x- min(x))/(max(x)-min(x)). However I want to do this operation directly on the table elements which have 150 rows and 42 features and I want to normalize each of these columns. Is there any one line procedure to do it without using for loop or something like that ? I know we could use curly and dot bracket indexing but the result is not gonna be a table though.

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 2 日
normalized_data = normalize(data, 'range'); %works on a table, normalizes to [0 1]

その他の回答 (1 件)

bharath pro
bharath pro 2020 年 7 月 2 日
If you can use z-score instead of min max, then you can directly do
data=normalize(data);
If you cant do that, then this works in one line.
data = (data - min(data, [], 1)) ./ max(data - min(data, [], 1), [], 1)
  4 件のコメント
D_coder
D_coder 2020 年 7 月 2 日
again I wanna preserve the table columns names I doubt this would do it
Walter Roberson
Walter Roberson 2020 年 7 月 2 日
data = array2table((table2array(data) - min(table2array(data), [], 1)) ./ max(table2array(data) - min(table2array(data), [], 1), [], 1), 'VariableNames', data.Properties.VariableNames);
However, the solution I posted using normalize() works directly on tables without that bother.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by