I need to scale the axes of a convolution function after plotting successive convolutions of x with itself. How do I scale the x axis for each so it has the correct support and how do I scale the convolutions to show that they are density functions?
21 次查看(过去 30 天)
显示 更早的评论
x=ones(1,20);
con0=conv(x,x);
con1=conv(x,con0);
figure(1);
plot(con0);
figure(2);
plot(con1);
Thanks in advance!
2 个评论
Rik
2020-2-4
编辑:Rik
2020-2-4
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
After every convolution the number of elements changes. Is this intentional?
If you use plot with only one input it will use the index as the x-value, so if you want a different axis you can simply supply an x-scale that suits you.
By 'showing that they are density distributions' do you mean they should be scaled to an area of 1?
采纳的回答
Rik
2020-2-4
Something like the code below should be close to what you want. Addapt as needed.
y=ones(1,20);
N=10;
output=cell(N,1);
output{1}=conv(y,y);
for n=2:N
output{n}=conv(y,output{n-1});
end
figure(1);clf(1)
%determine number of subplots
a=floor(sqrt(N));a=max(a,1);
b=ceil(N/a);
for n=1:N
subplot(a,b,n)
con=output{n};
x=linspace(0,1,numel(con));
con=con/trapz(x,con);%scale to unit area
plot(x,con);
title(sprintf('iteration %d',n))
axis([min(x) max(x) 0 5])
end
0 个评论
更多回答(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!