Plot SPIKES in MATLAB
조회 수: 6 (최근 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에서 Spectral Measurements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!