MATLAB: Help finding vector slope

linearslopevector

hello all,
I am trying to plot a vector named vec1, where
con = abs(g1-g2)/abs(t1:t2)*Fs));
vec1 = [g1*ones(1,Fs*t1),con*ones(1,Fs*t2), g2*ones(1,Fs*t3)];
What I want to see is a graph that has a linear slope from t1 to t2.
There must be something wrong with the con variable, but I can't get my head around it. Any help?
Thank you in advance

Best Answer

Try this :
Fs=1000;
T=(0:1/Fs:20-1/Fs);
V=zeros(1,length(T));
t1=3;
t2=5;
g1=7;
g2=4;
for t=1:length(T)
if T(t)<=t1
V(t)=g1;
elseif T(t)>t1 && T(t) <=t2
V(t)=-(g1-g2)/(t2-t1)*T(t)+1.65*g1;
elseif T(t)>t2
V(t)=g2;
end
end
figure,
plot(T,V)
axis([0 20 0 10]), xlabel('time in Seconds');
ylabel(' Magnitude dB');title(' Gain')
Related Question