1 view (last 30 days)

Hi. Suppose I have matrix A of size (m*n) e.g.

A = [12 44

93 43

128 44

145 41

180 41

220 40

280 40];

and the a,b,c and d values e.g.

a = 10

b = 95

c = 145

d = 290

As you know

a < A(1,1)

A(2,1) < b < A(3,1)

c = A(4,1)

d > A(7,1)

I want Matlab to do above process and search the a,b,c and d values in the A(:,1) and tell me that the a,b,c and d values are lesser than or greater than or equal or lying between what members of A(:,1).

Thanks for your help.

Andrei Bobrov
on 7 Nov 2017

A = [12 44

93 43

128 44

145 41

180 41

220 40

280 40];

a = 10;

b = 95;

c = 145;

d = 290;

ii_interval_of_1st_column_of_A = discretize([a,b,c,d],[-inf;A(:,1);inf]);

Andrei Bobrov
on 8 Nov 2017

ab = 180;

AA = [-inf;A(:,1);inf];

Aout = hankel(AA(1:end-1),AA(end-1:end));

ii = discretize(ab,AA);

out = Aout(ii,:);

t = bsxfun(@eq,out,ab);

out(xor(t(:,1),t(:,2)),2) = nan;

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502296

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502296

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502300

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502300

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502313

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502313

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502317

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/365720-finding-equal-values-between-values-greater-than-and-lesser-than-values-of-a-matrix-based-on-some#comment_502317

Sign in to comment.