Effacer les filtres
Effacer les filtres

Matlab value assignment acting weird

2 vues (au cours des 30 derniers jours)
prohi
prohi le 6 Mai 2017
Commenté : prohi le 6 Mai 2017
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 6 Mai 2017
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 commentaire
prohi
prohi le 6 Mai 2017
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!

Connectez-vous pour commenter.

Plus de réponses (1)

the cyclist
the cyclist le 6 Mai 2017
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 commentaire
prohi
prohi le 6 Mai 2017
Modifié(e) : prohi le 6 Mai 2017
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by