How to make statements intersect
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ani Asoyan
le 21 Jan 2020
Commenté : Ani Asoyan
le 21 Jan 2020
How can I make if command's statements intersect and after that receive the result. For example the answer for this code is 'noyesno' ....but I want it to be no, cause not all the elements of a and b are equal.
n=3
a=[0 1 2]
b=[1 1 3]
i=1
for i=1:n
if a(i)==b(i)
fprintf ('yes')
else
fprintf ('no')
end
end
0 commentaires
Réponse acceptée
Plus de réponses (1)
Bhaskar R
le 21 Jan 2020
Modifié(e) : Bhaskar R
le 21 Jan 2020
n=3; % length of the your vector i guess
a=[0 1 2];
b=[1 1 3];
% depends on n value
is_intersect = sum(a(1:n)==b(1:n))==n;
% if a and b vectors are same length
is_intersect = sum(a==b)==length(a);
if is_intersect
fprintf ('yes');
else
fprintf ('no');
end
Hope i got you !!
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!