How to change a value in one column dependent on another table column?

1 回表示 (過去 30 日間)
Mirthand
Mirthand 2021 年 4 月 15 日
編集済み: Mirthand 2021 年 4 月 15 日
I have a table (attached) with two columns.
I'd like to match Var1 and Var2.
For example all the Var2 should have the same Var1.
However, towards the end through Var1 it changes. I'd like to change those numbers to match the ones preceding. If you take a look at the Var2 (15), this would mean every row that has 15 should have 711. The goal is to replace the 429 with 711.
All the Var2 (30) should have 642.

採用された回答

David Hill
David Hill 2021 年 4 月 15 日
a=unique(table1.Var2);
for k=1:length(a)
b=find(table1.Var2==a(k));
for j=2:length(b)
table1.Var1(b(j))=table1.Var1(b(1));
end
end
  1 件のコメント
Mirthand
Mirthand 2021 年 4 月 15 日
編集済み: Mirthand 2021 年 4 月 15 日
Thank you, this works great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by