Another odd/even dilemma
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm new to MATLAB but last year I got a lot of experience in VBA so I'm not completely untrained in code.
I have code which is running a 'for' loop controlling time values.
I have 4 sets of near exact code, but with slight edits just for classification.
Basically I'm simulating 4 cylinders and I need to display their movement, and my fourth cylinder I want to use to simulate vibration.
My query is about how I can go about saying:
"if time is odd here, position head here, else position head here"
This seems real simple but I'm having trouble because I don't have much experience with 'for' loops.
Any response would be greatly appreciated
0 commentaires
Réponses (2)
Andrei Bobrov
le 15 Fév 2012
t = 1:20 % "your time"
% "a" - array (vector(1x20)) of position
% "1" - position for odd time
% "2" - position for even time
a = zeros(size(t))
a(1:2:end) = 1; % odd
a(2:2:end) = 2; % even
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!