Another odd/even dilemma
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Andrei Bobrov
on 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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!