Matlab value assignment acting weird
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
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...
Plus de réponses (1)
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
Voir également
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!