매트랩에서 조건이 만족하지 않으면 다시 처음부터 하게 끔 어떻게 하나요?

GA툴을 이용하여 최적값을 구하고자하는데 매트랩에서 조건이 만족하지 않으면 다시 처음부터 반복하게 끔 하고 싶습니다.
예를들어 행렬
A = rand(1,10)>0.5
B = [1 0 0 1 0 0 1 1 1 0]
C = zeros(1,10)
D = 0
for i=1:10
if A(1,i) == B(1,i)
C(1,i) = 2
elseif A(1,i)~=B(1,i)
C(1,i) = B(1,i)
end
for j = 1:10
if C(1,j)>=2
D=D+1
end
end
여기서가 문제인데 만약 D값이 4를 안넘으면 다시 처음부터 4를 넘을때까지 반복시키고 싶습니다. 이부분을 구현을 못하고 있는데 조언을 부탁드립니다.

댓글 수: 2

Walter Roberson
Walter Roberson 2015년 11월 24일
Approximate translation:
I would like to repeat it off again from the beginning if the conditions are not satisfied in MATLAB to obtain the best value for using the GA tool.
For example, the matrix
A = rand (1,10)> 0.5
B = [1 0 0 1 0 0 1 1 1 0]
C = zeros (1,10)
D = 0
for i = 1: 10
if A (1, i) == B (1, i)
C (1, i) = 2
elseif A (1, i) ~ = B (1, i)
C (1, i) = B (1, i)
end
for j = 1:10
if C (1, j)> = 2
D = D + 1
end
end
If 'If the D value is, where I would like to repeat again from the beginning until it exceeds 4 should not exceed the 4.
There unable to implement this section ask for advice.
Ji-hwan Hwang
Ji-hwan Hwang 2015년 11월 27일
thank you !

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 24일

0 개 추천

while true
... do your code ...
if D <= 4
break
end
%need to do it again if D exceeds 4
end
Note: your code is missing an 'end' for the 'for i'. I suspect it should go before the 'for j' but I am not certain of that.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2015년 11월 24일

댓글:

2015년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by