Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MATLAB中自定义离散函数图?_Matlab_Graph_Discrete Mathematics - Fatal编程技术网

如何在MATLAB中自定义离散函数图?

如何在MATLAB中自定义离散函数图?,matlab,graph,discrete-mathematics,Matlab,Graph,Discrete Mathematics,我想在MATLAB中绘制离散值,如下所示: stairs()和stem()绘制了类似的图,但我可以将其中一个配置为与上图类似吗 您必须自己创建绘图 %# 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 t

我想在MATLAB中绘制离散值,如下所示:

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


您必须自己创建绘图

%# 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:是的,我刚刚注意到。我修复了这个错误以及其他几个错误。现在它运行良好。