I would like to plot few values of a vector based on threshold setting from another vector.
1 view (last 30 days)
dpb on 3 Oct 2022
Edited: dpb on 3 Oct 2022
It works; you just can't see the single point that is left because the single point on a default line width without a marker just is too small/light to be able to see...
x=[1 2 3 4 5 6 7 8 9 10];
y=[1 2 3 4 5 6 7 8 9 10];
plot(x(y>3 & y<5),y(y>3 & y<5),'kx-')
lo=3; hi=8; % set different range; use variables instead of burying magic numbers in code..
plot(x(y>lo & y<hi),y(y>lo & y<hi),'r-') % now will show up with default line width
Here is place I like my "syntactical sugar" routine iswithin to reduce clutter in the user code by moving the comparisons to a lower level -- using it the above could be written as
lo=4;hi=4; % duplicate original, iswithin is inclusive
ix=iswithin(x,lo,hi)&iswithin(y,lo,hi); % logical addressing vector
plot(x(ix),y(ix),'kx') % plot original with a marker
where iswithin is
% returns T for values within range of input
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
I keep a "Utilities" subdirectory as part of my MATLABPATH just behind my current working directory in order; such general-use functions such as this reside there so are always available.