set of ranges in vector.

8 views (last 30 days)
Peter
Peter on 30 Jan 2014
Answered: Amit on 30 Jan 2014
I have a pool of 30 vectors with a set of values in them much like this(although much longer):
V = [a b c d e...]
V1 = [3.4 20.2 75.6 91.3 120.7...]
V2 = [3.2 21.7 76.6 94.3 122.7...]
V3 = [4.1 23.8 78.1 93.9 125.8...]
and so on.
As it can be seen, each value fluctuates slightly and within a range.
now I have a range of acceptable values for a b c d and e like this:
a accept = [2 5]; b accept = [20 25]; c accept = [70 80]; d accept = [90 100]; e accept = [120 130]
I need to be able to pick one vector (say V1) and check if all the values for a, b, c, d and e are within range.
I know how to do that for a single value this way:
inRange = (V1>2)&(V1<5);
ACCEPT V1 = V1(inRange);
This will spit out ACCEPT V1 = 3.4; as 3.4 is within range thus it makes it to output. Where I am stuck is: how can I make it look for multiple ranges so all the values will make it through (provided they fall in the range)?
another thing: I am trying to use this to filter out phantom readings(I shall call them PH), as in some of the vectors i have random extras readings that fall out of range such as:
V4 = [1.3 3.2 22.9 40.5 74.0 97.7 125.1 203.3...]
In other words: V4 = [PH 3.2 22.9 PH 74.0 97.7 125.1 PH...]
my end goal is to be able to run those ranges and get a corrected vector out that eliminates those phantom readings, getting ACCEPT V4 = [3.2 22.9 74.0 97.7 125.1...]
  1 Comment
Amit
Amit on 30 Jan 2014
what is the size of the vectors? Are they big?

Sign in to comment.

Accepted Answer

Chetan Rawal
Chetan Rawal on 30 Jan 2014
maximums = [5 25 80 100 130];
minimums = [2 20 70 90 120];
yesOrNoVector = (v1<maximums)&(v1>minimums);
% this outputs a vector or 0's and 1's where 1 means accept
acceptOrReject = all(yesOrNoVector);
% this is your answer. It returns 0 if at least one element of V1 is out of range. See >>doc all

More Answers (1)

Amit
Amit on 30 Jan 2014
minV = [2,20,70,90,120];
maxV = [5,25,80,100,130];
n = length(minV);
%I dont want to store each value seperately.
%acceptV is matrix with each row equivalent to acceptV1 etc.
acceptV = zeros(30,n);
for j = 1:30 % you said you have 30 vectors (I am assuming row vectors)
% You should initialize these before loop in all Vi's are same length
V = eval(['V' num2str(j)]);
Vx = repmat(V,n,1);
xx = (Vx - repmat(minV',1,numel(V))) > 0 & (-Vx + repmat(maxV',1,numel(V))) > 0;
acceptV(j,:) = (Vx(xx))';
end
If you badly want accept_V1 accept_V2 etc, you can see the treatment I did using eval (however I'll not advise it)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!