adding a value to all values in a table

So I have a 19880x1 table and I want to take the original values of the table, add 300 to those values, and create a new table of the new values. I've looked into varfun but I can't find a way to define func to add 300 without matlab yelling at me for this error: Operator '+' is not supported for operands of type 'table'.

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 4 月 11 日
Are all of the variables the same datatype, and in particular the same numeric datatype ?
Aaron Dubiansky
Aaron Dubiansky 2020 年 4 月 11 日
yes, it's just a table of numbers from a test, no text at all
Aaron Dubiansky
Aaron Dubiansky 2020 年 4 月 11 日
as in sensor data values.

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

回答 (2 件)

dpb
dpb 2020 年 4 月 11 日

0 投票

You address the variables in a table with the dot notation --
t.Var1=t.Var1+300; % store in place
t.Var2=t.Var1+300; % make new variable in existing table
u.Var1=t.Var1+300; % make a new table
Use whatever is your table variable in place of t and what is the variable name in the table for 'Var1' -- that's the default if don't provide any.
Walter Roberson
Walter Roberson 2020 年 4 月 11 日

0 投票

T = array2table(table2array(T)+300, 'variablenames', T.Properties.Variablenames);
Or
T{:, :} = T{:, :} + 300;

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

質問済み:

2020 年 4 月 11 日

回答済み:

2020 年 4 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by