Is this a bug??
3 ビュー (過去 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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165620/image.png)
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 で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!