Output argument "pixel_location" (and maybe others) not assigned during call to ......

1 vue (au cours des 30 derniers jours)
med-sweng
med-sweng le 27 Fév 2014
I'm trying to retrieve the pixel location of the pixel that meets the following criterion:
if s >= maximum
maximum = s;
pixel_location = sub2ind(size(p),i,j);
end
It seems that on the first run for instance, the criterion was not met, and thus, the "pixel_location" value was not returned. Thus, I got the following error:
Output argument "pixel_location" (and maybe others) not assigned during call to ......
In this case, what can I add in order to make the for-loop I'm running to continue without returning any value in this case. For instance, I tried adding an "else" and assigning some location (i.e; (1,1)). But, this may affect the output, wouldn't it?
Thanks.

Réponses (2)

Ashish Uthama
Ashish Uthama le 28 Fév 2014
Modifié(e) : Ashish Uthama le 28 Fév 2014
Setting pixel_location to empty ([]) in the else might be the right thing to do. MATLAB often uses [] to indicate 'nothing found'.
Of course, you would have to deal with this case further down in your code where you use pixel_location next. Setting to [] is essentially an indication (an in channel signaling if you will), that your down stream code would have to handle appropriately.

Image Analyst
Image Analyst le 28 Fév 2014
Step through it with the debugger, which I believe you already know, and see if it ever gets there. Evidently it does not, but it should get into the else. It has to go into one or the other. Anyway, put this as the first line of your code in that function
pixel_location = 0;
That way, no matter what happens, it will have an assigned value. Of course that value may be no good for the rest of the code and you may have subsequent errors.

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by