フィルターのクリア

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 Center および File ExchangeLine Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by