필터 지우기
필터 지우기

Plot SPIKES in MATLAB

조회 수: 8 (최근 30일)
Susan
Susan 2011년 4월 2일
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')

채택된 답변

Matt Fig
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' )
  댓글 수: 1
Susan
Susan 2011년 4월 2일
Thanks a lot that helped me a lot.. I really appreciate it :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by