# How do i do x1<=x<=x2 in matlab?

2 Ansichten (letzte 30 Tage)
Alexander am 11 Apr. 2023
Kommentiert: Les Beckham am 11 Apr. 2023
I am trying to enter x1<=x<=x2 for matlab. however i am useless at coding and i cannot find a way to get this to work.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Les Beckham am 11 Apr. 2023
Bearbeitet: Les Beckham am 11 Apr. 2023
You have to split up the compound condition into two conditions:
(x1 <= x) && (x <= x2)
If these terms are scalars, that will generate a scalar logical value. If they are not scalars, you should read about logical indexing.
Also, if you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Les Beckham am 11 Apr. 2023
You are quite welcome.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Antoni Garcia-Herreros am 11 Apr. 2023
Hello Alexander
You should use the & statement
x=1:10;
%Let's say you want to find the values of x between 3 and 7
x1=3;
x2=7;
x>=3 & x<=7
ans = 1×10 logical array
0 0 1 1 1 1 1 0 0 0
x(x>=3 & x<=7)
ans = 1×5
3 4 5 6 7
##### 1 KommentarKeine anzeigenKeine ausblenden
Alexander am 11 Apr. 2023
ohhh. thank you

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!