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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

SungJun Cho
SungJun Cho el 15 de Abr. de 2021
Editada: SungJun Cho el 15 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by