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!