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

조회 수: 1 (최근 30일)
Mirthand
Mirthand 2021년 4월 15일
편집: SungJun Cho 2021년 4월 15일
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