Another odd/even dilemma
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Andrei Bobrov
am 15 Feb. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!