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

1 次查看(过去 30 天)
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.

回答(2 个)

Ashish Uthama
Ashish Uthama 2014-2-28
编辑:Ashish Uthama 2014-2-28
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 2014-2-28
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.

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by