How can I get a plot like this on Matlab?

7 ビュー (過去 30 日間)
Federico Bonaldo
Federico Bonaldo 2019 年 2 月 7 日
コメント済み: Federico Bonaldo 2019 年 2 月 7 日
Hi,
Does anyone know how do I obtain a figure like the one in attachment?
I have x axis and y axis data corresponding to the top (or bottom) of the blue sticks, so that if I plot it in Matlab it gives me just a point at the end of the stick. What I would like to do is to draw that continuous line which would represent the spectrum and giving it a definite peak width (the same for all the peaks is ok); if also the blue stick can be added it would be great.
I am not very good with Matlab, so I hope you understand what I mean and someone can solve my problem.
Thanks

採用された回答

Rik
Rik 2019 年 2 月 7 日
You can do something like this:
%set some mu,height,sd pairs
%(replace with your actual data)
mu_list=[1200 1350 1500 1550 1600];
height_list=[300 100 100 200 75];
sd_list=[20 20 100 20 40];
%define the x-scale
x=linspace(1100,1700,1000);
%define a scalable gaussian
G_fun=@(x,mu,sd) 1/sqrt(2*pi*sd^2)*exp(-(x-mu).^2/(2*sd^2));
G_fun_scaled=@(x,mu,sd,scale) scale*sqrt(2*pi*sd^2)*G_fun(x,mu,sd);
%loop over the gaussians to get the sum
figure(1),clf(1)
y=zeros(size(x));
for n=1:numel(mu_list)
[mu,sd,scale]=deal(mu_list(n),sd_list(n),height_list(n));
y=y+G_fun_scaled(x,mu,sd,scale);
plot([mu mu],[0 scale],'b'),hold on
end
plot(x,y,'k')
  1 件のコメント
Federico Bonaldo
Federico Bonaldo 2019 年 2 月 7 日
It works perfectly, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by