Changing a a value in table column dependent on another column.

2 次查看(过去 30 天)
In the table I would like column e to replace the the first two 78 with 1. The 1 value should match with column d and the 2 value.
e = [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 78 78 78 78 78 78 78 78 78 78]
e = e'
d = [ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 56 56 56 56 56 56 56]
d = d'
tableh = table(e, d)
OUTPUT for current Table:
tableh =
25×2 table
e d
__ __
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
78 2
78 2
78 2
78 56
78 56
78 56
78 56
78 56
78 56
78 56

采纳的回答

SungJun Cho
SungJun Cho 2021-4-15
编辑:SungJun Cho 2021-4-15
You can just do
e = [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 78 78 78 78 78 78 78 78 78 78];
e = e';
d = [ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 56 56 56 56 56 56 56];
d = d';
e(d==2) = 1;
tableh = table(e,d);
to have value 1 in e whenever you have value 2 in d.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by