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

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

Réponse acceptée

David Hill
David Hill le 15 Avr 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by