Plot SPIKES in MATLAB
9 次查看(过去 30 天)
显示 更早的评论
Hello guys..
I am struggling with this for a while and I need help urgently.. I have the code for generating the possion process but I need it to generate spikes instead in the axis line and the function (sin/cos) in to be smooth, at the moment the spikes is generated in the function so the function is not smooth and i dont want this and I believe its a slight change what is missing but I cant figure it out.. I put the code below and a link to show the spikes am talking about..............
Thanks in advance :) Many Thanks your help will be appreciated it..
function S = nonhomogeneousPossion(lambda0,lambda,T)
t = -5;
I = 0;
S = [];
u = rand;
t = t - log(u)/lambda0;
while t <= T
u = rand;
if (u <= lambda(t)/lambda0)
I = I+1;
S(I) = t;
end
u = rand;
t = t - log(u)/lambda0;
end
test script..
lambda0 = 50; % Maximum value of lambda
T = 1;
lambda =@(x) lambda0 * cos(x); % lambda0(t)/lambda0
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot 121
plot(S,lambda(S),'.')
xlabel('t')
ylabel('lambda(t)')
lambda = @(x) lambda0 *sin(x);
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot 122
plot(S,lambda(S),'.')
xlabel('t')
0 个评论
采纳的回答
Matt Fig
2011-4-2
I looked at your pdf, and it is not entirely clear where you want to plot the lines. This might give you a head start, put it at the end of your test script and maximize the figure:
for ii = 1:length(S)
line([S(ii) S(ii)],[lambda(S(ii)) lambda(S(ii))-2],'color','r' )
end
The FOR loop could be replaced by this:
line(repmat(S,2,1),repmat([0;1],1,length(S)),'color','r' )
Now the spikes are on the x-axis. Hope this helps...
EDIT
How's this?
lambda0 = 50; % Maximum value of lambda
T = 1;
lambda =@(x) lambda0 * cos(x); % lambda0(t)/lambda0
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot(1,2,1)
plot(S,lambda(S),'-')
xlabel('t')
% ylabel('lambda(t)')
lambda = @(x) lambda0 *sin(x);
S = nonhomogeneousPossion(lambda0,lambda,T);
subplot(1,2,2)
plot(S,lambda(S),'-')
xlabel('t')
X = linspace(min(S),max(S),200);
Y = pchip(S,lambda(S),X);
plot(X,Y,'-b',S,lambda(S),'ok')
line(repmat(S,2,1),repmat([0;1],1,length(S)),'color','r' )
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!