필터 지우기
필터 지우기

Matlab value assignment acting weird

조회 수: 1 (최근 30일)
prohi
prohi 2017년 5월 6일
댓글: prohi 2017년 5월 6일
Hi!
I have the following code (as a part of a bigger program, mainly for image processing):
P_hatso3_x = P_hatso2_x;
w6 = 1;
disp('axax')
y_alap6 = P_hatso2_y
disp('dasd')
while (w6 == 1)
if (pixel_labels(y_alap6,P_hatso3_x) == szegm_lab)
y_alap6 = y_alap6 - 1;
else
w6=0;
P_hatso3_y = y_alap6;
end
end
Now when I run it, it returns with the following command window:
axax
y_alap6 =
72
dasd
Subscript indices must either be real positive integers or logicals.
Error in kmeans_proba_advanced (line 293)
if (pixel_labels(y_alap6,P_hatso3_x) == szegm_lab
so it returns with an error, because the
pixel_labels
binary array can not be indexed with the variable called
y_alap6
because it has a value of 0 . However, as we see on the command window, the value 72 had been assigned to it before (between 'axax' and 'dasd' strings), but it somehow magically disappeared/changed/got unassigned 3 lines later. I am really confused, as this only comes up for some of the pictures I am trying to process with this program, I just can't find out why this could be. Can someone please help me?

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 6일
You have
y_alap6 = y_alap6 - 1;
within your loop, and you are not displaying anything when you do that assignment, so you have no notice that is changing. What happens if it ends up counting backwards all the way to 0?
Your test is pixel_labels(y_alap6,P_hatso3_x) == szegm_lab but suppose that is true all the way ? It is true at row 1, so you decrement the row to 0, and then you try looking at row 0...
  댓글 수: 1
prohi
prohi 2017년 5월 6일
This is indeed it, sorry for wasting everyones time! Really beginner mistake, but I am still a beginner. The test is not supposed to be true all the way to 0 based on the visual examination of the image, but it indeed is this time!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2017년 5월 6일
You don't mention the value of P_hatso3_x, which is also used as an index. Are you also confident that it is a non-zero integer?
Can you set a breakpoint at that actual line of code, and see that values at that moment?
  댓글 수: 1
prohi
prohi 2017년 5월 6일
편집: prohi 2017년 5월 6일
Even more weirdly, when I set a breakpoint to the
y_alap6 = P_hatso2_y
and
if (pixel_labels(y_alap6,P_hatso3_x) == szegm_lab)
lines it just works fine every time and y_alap6 gets the correct value assigned to it.
P_hatso3_x
has the correct value at every run, I already checked that, the problem is with
y_alap6

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by