How to adjust a vector using an if function
Afficher commentaires plus anciens
Hello every body, below you can find my code. I want to customize the vector A, so if one condition is true the vector A should be adjusted.So a 1 should be added if C is smaller than 0 and a 1 should be subtracted if C is greater than 0. For example: A=[0,0,0,2,2,2,2,....]. But every time my vector A stays the same, only containing 1. Thanks
A= ones(100,1);
B=2*rand(100,1);
C=A-B;
for k=1:length(A);
if C(k)<0
A(k)+1;
else if C(k)>0
A(k)-1;
else A(k)
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Stress and Strain dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
