Is this a bug??
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 28 de Jun. de 2017
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.
Respuestas (3)
Image Analyst
el 28 de Jun. de 2017
Break it up into smaller chunks until you find out which chunk is false.
2 comentarios
Image Analyst
el 28 de Jun. de 2017
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
el 28 de Jun. de 2017
Editada: James Tursa
el 28 de Jun. de 2017
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 comentarios
Jan
el 28 de Jun. de 2017
Editada: Jan
el 28 de Jun. de 2017
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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!