How to make the condition for checking the matrix value ?

1 vue (au cours des 30 derniers jours)
Akash Pal
Akash Pal le 26 Nov 2022
Commenté : Akash Pal le 28 Nov 2022
function [popnew1,mutated] =mutation(A,Pm)
mutated = find(rand(size(A))<Pm);
popnew1 = A;
% Why my this condition is not working
if A(mutated)== 1
popnew1(mutated) = 2-A(mutated);
else
popnew1(mutated) = 1-A(mutated);
end
%
end
Please Help me why my this condition part is not working Where A is 3x8 matrix and Pm=0.1 .
Where is the problem in my condition ?

Réponse acceptée

VBBV
VBBV le 26 Nov 2022
popnew1 = 2-A(mutated);
  10 commentaires
VBBV
VBBV le 27 Nov 2022
if A(mutated) == 1
popnew1(mutated) = 2-popnew1(mutated); % in place of A put popnew1
else
popnew1(mutated) = 1-popnew1(mutated); % in place of A put popnew1
end
Akash Pal
Akash Pal le 28 Nov 2022
Thank you for your suggestion .

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by