Is this a bug??

3 次查看(过去 30 天)
Elvis Somers
Elvis Somers 2017-6-28
编辑: Jan 2017-6-28
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 个评论
Adam
Adam 2017-6-28
What are the values in question? Are they doubles?
Jan
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
Image Analyst 2017-6-28
Break it up into smaller chunks until you find out which chunk is false.
  2 个评论
Elvis Somers
Elvis Somers 2017-6-28
What exactly am i supposed to break up? The form of the code is
a = b;
a == b
ans = 0
How?? This doesn't make any sense right. Can the mistake be in the "a" while both a's are the same?
Image Analyst
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
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

Jan
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 ?

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by