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

조회 수: 1 (최근 30일)
Alexander
Alexander 2023년 4월 11일
댓글: Les Beckham 2023년 4월 11일
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.
Please help

채택된 답변

Les Beckham
Les Beckham 2023년 4월 11일
편집: Les Beckham 2023년 4월 11일
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
Alexander
Alexander 2023년 4월 11일
ohhh. thank you
Les Beckham
Les Beckham 2023년 4월 11일
You are quite welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 4월 11일
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by