A value belongs to an interval

조회 수: 2 (최근 30일)
Mohamed Saleh
Mohamed Saleh 2018년 2월 19일
편집: Walter Roberson 2018년 2월 20일
Hi. Please I need a help with the following,
if 4<A && A<5
display(' No value')
else
display(' There is a value')
end
if statement does not give the right values of A. Please any one can help me why it does not work properly?
  댓글 수: 2
John D'Errico
John D'Errico 2018년 2월 19일
If you have a vector in A, this is the wrong thing to do. An if statement does not apply to each element of a vector, independently.
Mohamed Saleh
Mohamed Saleh 2018년 2월 19일
Yes A is a vector. Please, how can I introduce "if" then?

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

답변 (2개)

Roger Stafford
Roger Stafford 2018년 2월 19일
To display the values you want write:
A(4<A&A<5)
  댓글 수: 1
Mohamed Saleh
Mohamed Saleh 2018년 2월 20일
Thank you very much for your response.

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


Akira Agata
Akira Agata 2018년 2월 19일
I think what you want to do would be like this. BTW, display function is not recommended. Please use disp function instead.
% Sample data
A = 5*rand(10,1);
idx = (4 < A) & (A < 5);
for kk = 1:numel(idx)
if idx(kk)
disp('No value')
else
disp('There is a value')
end
end
  댓글 수: 1
Mohamed Saleh
Mohamed Saleh 2018년 2월 20일
Thanks a lot for your answer.

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

카테고리

Help CenterFile Exchange에서 Switches and Breakers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by