MATLAB: Creating a Function based on Time

functiontime

As the title suggests I'm trying to create a function of time that computes lift and drag coefficients for the first 5 seconds and then what they are after 5 seconds. I don't have too much MatLab experience so I'm probably not doing this right. Can someone please help?
function[CL, CD, CP] = LiftandDrag(t, CLi, CDi)
t = 1:100;
CDi = 0.01; %Initial canopy Drag Coefficient
CLi = 0.0; %Initial canopy Lift Coefficient
if t < 5
CL = .2*t+CLi;
CD = 0.038*t+CDi; %drag coeffcient of chute
CP = 2; %drag of payload
elseif t > 5
CL = 1; %Inflated canopy Lift Coefficient
CD = .2; %Inflated canopy Drag Coefficient
CP = 2; %Payload Drag Coefficient
end

Best Answer

Vectorize. Logical indexing.
function [CL, CD, CP] = calcLiftAndDrag
t = 1:100;
CDi = 0.01; %Initial canopy Drag Coefficient
CLi = 0.0; %Initial canopy Lift Coefficient
[CL, CD, CP] = LiftandDrag(t, CLi, CDi);
function[CL, CD, CP] = LiftandDrag(t, CLi, CDi)
CL = zeros(size(t));
CD = zeros(size(t));
CP = zeros(size(t));
mask = t <= 5;
CL(mask) = .2*t(mask)+CLi;
CD(mask) = 0.038*t(mask)+CDi; %drag coeffcient of chute
CP(mask) = 2; %drag of payload
CL(~mask) = 1; %Inflated canopy Lift Coefficient
CD(~mask) = .2; %Inflated canopy Drag Coefficient
CP(~mask) = 2; %Payload Drag Coefficient