【问题标题】:How to customize a discrete function plot in MATLAB?如何在 MATLAB 中自定义离散函数图?
【发布时间】:2010-10-23 10:32:58
【问题描述】:

我想像这样在 MATLAB 中绘制离散值:

stairs()stem() 绘制了相似的图,但我可以将其中一个配置为类似于上图吗?

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

【问题讨论】:

    标签: matlab graph discrete-mathematics


    【解决方案1】:

    你必须自己创建情节。

    %# 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')
    

    【讨论】:

    • @sekmet64:是的,我刚刚注意到。我修复了这个问题,以及其他几个错误。现在它运行良好。
    猜你喜欢
    • 2020-04-30
    • 1970-01-01
    • 2023-04-01
    • 2021-12-24
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多