Is this a bug??
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey, im getting the ouput shown in the picture which makes absolutely no sense to me. Im quite sure it should be one since is just stated it is true. Anyones knows what I could be doing wrong?
댓글 수: 2
Jan
2017년 6월 28일
Please post code as text and not as screenshot. It is tedious and prone to typos to use this image for writing an answer. It would be easier to help you, when we can copy&paste the code.
답변 (3개)
Image Analyst
2017년 6월 28일
Break it up into smaller chunks until you find out which chunk is false.
댓글 수: 2
Image Analyst
2017년 6월 28일
Come on. Break it up into smaller terms, like usual in debugging. Like
a = reverseoccupations2(j, 9:38)
b = find(a==1, 1, 'first')
c = i + k + b - 1;
d = reverseoccupations2(j, c)
and so on for the rest of it with reversestepsizes. Don't put semicolons at the end of the lines.
James Tursa
2017년 6월 28일
편집: James Tursa
2017년 6월 28일
We really need to know the data types and values involved. E.g., with int8
>> a = int8([0 0])
a =
0 0
>> b = 1.5
b =
1.5000
>> a(1) = b
a =
2 0
>> a(1) == b
ans =
0
or with doubles
>> b = nan
b =
NaN
>> a = b
a =
NaN
>> a == b
ans =
0
댓글 수: 0
Jan
2017년 6월 28일
편집: Jan
2017년 6월 28일
No, the show code is not equivalent to:
a = b
a == b
The indexing is modified:
a(find(a == 1)) = b
Now a has been changed and find(a == 1) can reply another value. With your code (and with using shorter names for the variables (again: please do not post screenshots for code):
ro(j, i+k+(find(ro(j, 9:38) == 1, 1, 'first')-1)+rs(j,i)*((rp(j,i)-k) > 0)) = temp;
But now a value of ro has been changed, such that
find(ro(j, 9:38) == 1, 1, 'first')
need not be the same index as before.
Such problems can be found easily, if you follow Image Analysts suggestion to break down the code into pieces:
index1 = i+k+(find(ro(j, 9:38) == 1, 1, 'first') - 1)
ro(j, i+k+(find(ro(j, 9:38) == 1, 1, 'first')-1)+rs(j,i)*((rp(j,i)-k) > 0)) = temp;
index2 = i+k+(find(ro(j, 9:38) == 1, 1, 'first') - 1)
Is index1==index2 ?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!