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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

SungJun Cho
SungJun Cho il 15 Apr 2021
Modificato: SungJun Cho il 15 Apr 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.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by