How to make the condition for checking the matrix value ?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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 ?
채택된 답변
VBBV
2022년 11월 26일
popnew1 = 2-A(mutated);
댓글 수: 10
You need to assign popnew1 as above, after substituting the indices in A matrix to get new popnew1.
Can you tell me which steps i need to change in my coding ? Because i did not understand your advise .
If you can show me in my coding .
Thanks in advance .
Or can you set any condition where if the mutated point value is zero then only it will change to 1 ,Otherwise if the mutated point is 1 then it will not be changed ,means it will be same as 1
Why do you want substitute the mutated indices in popnew1 instead of assigning it ?. Look at the change suggested for the line in beginning. mutated is indices vector where the values of A are less than Pm.
if A(mutated)== 1
popnew1 = 2-A(mutated);
else
popnew1 = 1-A(mutated);
end
Sorry to say this logic is not working ,its only showing the mutated point
May be the below change you need to do
A = eye(3,8) % The A matrix
A = 3×8
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
Pm = 0.1;
[popnew1,mutated] = mutation(A,Pm)
popnew1 = 3×8
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
mutated = 21×1
2
3
4
6
7
8
10
11
12
13
function [popnew1,mutated] = mutation(A,Pm)
mutated = find(A<Pm);
popnew1 = A;
% Why my this condition is not working
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
%
end
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
Thank you for your suggestion .
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

