In for loop, add same fractional value to all non-integers in the vector
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
balsip
il 8 Mag 2017
Commentato: David Goodmanson
il 8 Mag 2017
Hello,
In vector A, I have values that are either integers or fractional values (all are X.3000). I'd like to add 0.2 to all fractional values, so that all non-integers are X.5000.
This is the code I have so far, and it's doing what I want it to, but only to the last value in the vector! What's the hiccough preventing it from being applied through the whole vector?
for i=length(A)
if floor(A(i)) ~= ceil(A(i))
A(i)=A(i)+.2;
end
end
0 Commenti
Risposta accettata
David Goodmanson
il 8 Mag 2017
Modificato: David Goodmanson
il 8 Mag 2017
HI balsip, try
for i = 1:length(A)
2 Commenti
David Goodmanson
il 8 Mag 2017
yes, we've all been there, where you look at something in plain sight and don't see it.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!