A value belongs to an interval

19 vues (au cours des 30 derniers jours)
Mohamed Saleh
Mohamed Saleh le 19 Fév 2018
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 commentaires
John D'Errico
John D'Errico le 19 Fév 2018
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 le 19 Fév 2018
Yes A is a vector. Please, how can I introduce "if" then?

Connectez-vous pour commenter.

Réponses (2)

Roger Stafford
Roger Stafford le 19 Fév 2018
To display the values you want write:
A(4<A&A<5)
  1 commentaire
Mohamed Saleh
Mohamed Saleh le 20 Fév 2018
Thank you very much for your response.

Connectez-vous pour commenter.


Akira Agata
Akira Agata le 19 Fév 2018
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 commentaire
Mohamed Saleh
Mohamed Saleh le 20 Fév 2018
Thanks a lot for your answer.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by