필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

HOW TO GET BINARY OUTPUT IN A MATRIX TEMPLATE WITH GIVEN CONDITIONS

조회 수: 1 (최근 30일)
PRANAY DISHAN
PRANAY DISHAN 2018년 2월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello everyone, I am not able to get the required output. The following is my code and values. Can anyone please resolve this for me. Am working on Particle Swarm Optimization for Inventory Control.
if particle(i).VelocitySIG>particle(i).Random
particle(i).Sol=particle(0).Sol;
else
particle(i).Sol=particle(1).Sol;
end
The values achieved on executing are as follows:
particle(1).VelocitySIG= 0.9709 0.0961 0.7857 0.2967 0.1267 0.9594
particle(1).Random=0.7350 0.9706 0.8669 0.0862 0.3664 0.3692
particle(1).Sol= 1 1 0 1 1 0
The expected values of particle(1).Sol is 1 0 0 1 0 1. But the output is 1 1 0 1 1 0
Please Help... Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 1일
Your line
particle(i).Sol=particle(0).Sol;
attempts to access particle #0, which is an invalid index.
You appear to be testing one a vector VelocitySIG against a vector Random. When you have a statement of the form
if vector > vector2
then in MATLAB the condition is only considered true if all of the values are true,
if all(vector > vector2)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by