help finding vector slope
17 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Youssef Khmou
2013-2-12
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')
2 个评论
Youssef Khmou
2013-2-12
编辑:Youssef Khmou
2013-2-12
Tony, yes i forgot to mention that :
So your function in the 2dn region is defined as : y =ax+ b with negative slope :
vect(t) = a*T(t) + constant .
The slope is a= g1-g2/(t2-t1)= -3/2 .
to derive the constant : you take the initial condition :
At t=t1 vect(t1)=g1=a*t1+constant => constant=g1-a*t1=11.5 .
you can put 11.55 instead of g1*1.65 ,the reason i did g1*1.65 is because i derived the solution before you gave the details g1,t1,.. it was an approximation rather than solution from ax+b.
更多回答(4 个)
the cyclist
2013-2-12
You don't really give enough detail to diagnose this, but I did notice that in the line
con = abs(g1-g2)/abs(t1:t2)*Fs));
the parentheses are balanced, so it's not a valid MATLAB statement.
0 个评论
Youssef Khmou
2013-2-12
hi, you have to declare all variables in your example like others said so as to examine the code , but now details are missing .
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!