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
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?
GS25
GS25 2020-2-4
Thanks for your assistance. I'll take a look for next time.
The change in number of elements is intentional, I want to convolve 10 times, what I posted was a sample for the first two.
Yes that is exactly it, I need to find a way to scale the plot to an area of 1.
Thank you Rik.

请先登录,再进行评论。

采纳的回答

Rik
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 个)

类别

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