سؤال

أرغب في رسم القيم المنفصلة في Matlab مثل هذا:

stairs() و stem() قم بعمل قطع متشابهة ولكن هل يمكنني تكوين أحدها لتبدو مثل الصورة أعلاه؟

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

هل كانت مفيدة؟

المحلول

عليك أن تخلق المؤامرة بنفسك.

%# 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')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top