MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中自定义离散函数图? (https://www.labfans.com/bbs/showthread.php?t=24043)

poster 2019-12-10 20:48

如何在MATLAB中自定义离散函数图?
 
我想像这样在MATLAB中绘制离散值:

[IMG]https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Discrete_probability_distribution.svg/200px-Discrete_probability_distribution.svg.png[/IMG]

stairs()和stem()绘制相似的图,但是我可以配置其中之一看起来像上面的图像吗?

[URL]http://www.mathworks.com/help/techdoc/ref/plottype-stairs.gif[/URL] [URL]http://www.mathworks.com/help/techdoc/ref/plottype-stem.gif[/URL]



[B]回答:[/B]

您必须自己创建情节。

%# create some random data data = randn(100,1); %# sort ascending data = sort(data(:)); %# make column vector, just in case %# count nData = length(data); %# create data to plot (open, closed circles) yData = linspace(0,1,nData-1)'; %'# SO formatting closedX = data(1:end-1); closedY = yData; openX = data(2:end); openY = yData; %# lines are from open to close with NaN for where there should be no line lineX = [closedX,openX,NaN(nData-1,1)]'; %'# SO formatting lineX = lineX(:); lineY = [closedY,openY,NaN(nData-1,1)]'; %'# SO formatting lineY = lineY(:); %# plot figure %# I like to open a new figure before every plot hold on plot(lineX,lineY,'r') plot(closedX,closedY,'ro','MarkerFaceColor','r') plot(openX,openY,'ro','MarkerFaceColor','w')

[url=https://stackoverflow.com/questions/4003536]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:16

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.