Hey, I have a problem with changing the colours on my graph conditionally; my function is as follows
function [t,vx,vy] = Q3_1400000(rocket,brake)
[t,ax,ay] = getAcceleration(rocket,brake);
vx = 0; vy = 0;
for n = 1:999;
vx(n+1) = vx(n) + ax(n+1); vy(n+1) = vy(n) + ay(n+1); k = 1:length(vx);if vy(k) > vx(k) c = 'r';else c = 'b';endend
plot(t,vx(k),c);
hold on
grid on
plot(t,vy(k),c);
xlabel('Time (s)');
ylabel('Velocity (m/s)');
title('\Velocity data for the rocket sled');
legend({'v_x','v_y'})
end
For some reason when the graph plots, the colour will always be the ' else ' colour and won't change at all. Does anybody know the solution to this please ?
Thanks
Best Answer