フィルターのクリア

How can I change value in a table?

321 ビュー (過去 30 日間)
zeezo
zeezo 2018 年 3 月 6 日
コメント済み: Star Strider 2018 年 3 月 6 日
I have this code
d={'first';'second';'third';'forth'};
L=[2;35;4;65];
T=table(d,L)
after the result came,I would like to change the 35 to zero. How can I change the table value?

採用された回答

Image Analyst
Image Analyst 2018 年 3 月 6 日
Adding to Star's way, here are some other ways:
T{2, 2} = 0 % Set row 2, column 2 to 0.
T.L(2) = 0 % Set row 2 of column "L" to 0 (L not required to be column #2 in this case)
It depends on what you know about the 35. Star's way will set all values of 35 in column "L" to zero. The ways I gave are if you know that it's row 2 in column 2 (the "L" column), and it's row 2 you want to set, instead of all the rows with a value of 35.
It can be tricky figuring out when to use braces, parentheses, or brackets in MATLAB. Tables are sort of like cell arrays in a way, it's just that every item in a column must be of the same type. So the FAQ http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F may help you to figure out when to use braces, parentheses, or brackets.

その他の回答 (1 件)

Star Strider
Star Strider 2018 年 3 月 6 日
One approach:
d={'first';'second';'third';'forth'};
L=[2;35;4;65];
T=table(d,L)
idx = find(L == 35);
T.L(idx) = 0
T =
4×2 table
d L
________ __
'first' 2
'second' 35
'third' 4
'forth' 65
T =
4×2 table
d L
________ __
'first' 2
'second' 0
'third' 4
'forth' 65
  2 件のコメント
zeezo
zeezo 2018 年 3 月 6 日
Thank you very much.
I want to make the change deponent on the location not for a specific value. maybe there are more than on values = 35 but I want to change (1,2) only
Star Strider
Star Strider 2018 年 3 月 6 日
Easy enough:
T.L(2) = 0;

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

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by