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

1 vue (au cours des 30 derniers jours)
Mirthand
Mirthand le 15 Avr 2021
Modifié(e) : SungJun Cho le 15 Avr 2021
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

Réponse acceptée

SungJun Cho
SungJun Cho le 15 Avr 2021
Modifié(e) : SungJun Cho le 15 Avr 2021
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.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by