[英]Plot with discrete X-axis range in MATLAB
我有一個數字數組,稱為samples
, 大小為[1 250] 。 我想繪制它,以使范圍[100 110]
和[200 350]
中的點不顯示在圖中。
查看代碼中的注釋:
function q47150844
%% Omit Y values in a certain range:
% Generate some data:
samples = randi(500,1,250);
% Choose valid points:
valid = (samples < 100) | (samples > 110 & samples < 200) | (samples > 350);
% Set invalid points to NaN:
samp_proc = samples; samp_proc(~valid) = NaN;
% Plot the remaining data:
figure(); plot(samp_proc,'.'); hold on;
% Plot the rejection limits for verification:
plot([0 250],[100 100],':r',[0 250],[110 110],':r',...
[0 250],[200 200],':r',[0 250],[350 350],':r');
%% Omit X values in a certain range:
xrange = 1:numel(samples);
valid = (xrange < 100) | (xrange > 110 & xrange < 200) | (xrange > 350);
xrange(~valid) = NaN;
figure(); plot(xrange,samples,'.'); hold on;
plot([100 100],ylim,':r',[110 110],ylim,':r',...
[200 200],ylim,':r',[350 350],ylim,':r');
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.