Update elements in matrix with condition
Ältere Kommentare anzeigen
I have a large matrix (1st image). I need to update element in column 3&4 whenver it becomes 0 in column 5 or integer changes in column 6.
And I want to update it with sum from column 1 and 2.
See second image for more clarity.

My matrix should perform this for all the rows.

1 Kommentar
Ravi Kumar
am 26 Okt. 2021
Akzeptierte Antwort
Weitere Antworten (1)
Rik
am 26 Okt. 2021
N = size(P,1);
for k = 1:1:N
if P(k,5) == 0
P(k,3) = P(k,1) + P(k,3);
end
end
Similar code will allow you to edit when the value changes:
if k>1 && A(k-1)==A(k)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!