MATLAB Answers

0

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

Asked by med-sweng on 27 Feb 2014
Latest activity Answered by Image Analyst
on 28 Feb 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.

  0 Comments

Sign in to comment.

Tags

No tags entered yet.

2 Answers

Answer by Ashish Uthama on 28 Feb 2014
Edited by Ashish Uthama on 28 Feb 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.

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 28 Feb 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.

  0 Comments

Sign in to comment.