# Check which range an upper & lower limit lies within

2 vues (au cours des 30 derniers jours)
mark le 23 Mar 2023
Commenté : mark le 23 Mar 2023
Hi,
I have a set of horizontal coordinates (Y1 and Y2) which define a rectangle. Y1 defines the LHS top edge point & Y2 the RHS bottom edge point (see image). I also have a table (T) which has the horizontal location of each section of a planform. For example:
Y1 = 3.4;
Y2 = 7.1;
T = table([0.1, 0.75, 3.0, 8.2, 9.1]);
T = rename vars(T, T.Properties.VariableNames, ["L1", "L2", "L3", "L4", "L5"]);
I want to see which range (e.g. L1-L2, L2-L3......) Y1 and Y2 (i.e the rectangle) lies in (Y1 is the lower limit and Y2 is the upper limit). So for this example, I know the rectange is between L3 and L4 but I want the code to tell me this. I am stuck on how to code this. Any suggestions will be appreciated. Thank you
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Matthieu le 23 Mar 2023
Hi,
I would recommand using a cell object instead of table, or a matrix depending on your needs, as shown below :
Y1 = 3.4;
Y2 = 7.1;
T = {0.1, 0.75, 3.0, 8.2, 9.1}
T = 1×5 cell array
{[0.1000]} {[0.7500]} {[3]} {[8.2000]} {[9.1000]}
Tmat = horzcat(-inf,cell2mat(T),inf) ; % -inf and inf are here to tell your limits are out of L bounds
Y = [Y1,Y2] ;
Range = cell(1,length(Y)) ;
for i = 1:length(Y)
for k = 1:length(T)-1
if T{k} < Y(i) & T{k+1} > Y(i) ;
Range{i} = [T{k},T{k+1}] ;
end
end
end
Range
Range = 1×2 cell array
{[3 8.2000]} {[3 8.2000]}
This is coded in a horrible way and I'm sure there are better ways to do it, but if I'm not mistaken this is what you needed.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
mark le 23 Mar 2023
this did exactly what I wanted! thanks a bunch

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by