0

What value will get stored in handles.axes if image is present and if the image is not present? I want check the condition whether image is present or not, and i implemented this

if handles.axes1==0
msgbox('Please insert image. . .', 'Error. . .');
end

but this is not working, please suggest me the best way of doing this.

Chethan
  • 213
  • 3
  • 7
  • 19
  • How do you generate `handles.axes1` in the first place? – Oleg Apr 27 '13 at 12:46
  • `axes(handles.axes1); imshow(fname);` – Chethan Apr 27 '13 at 12:53
  • There is a difference between [axes](http://www.mathworks.com/help/matlab/ref/axes.html) graphic object and [image](http://www.mathworks.com/help/matlab/ref/image.html) object. Also use `ishghandle` to test if the handle is valid – Amro Apr 27 '13 at 15:46

1 Answers1

1

Your axes handle will not be modified by the call to imshow - this plots an image on an axes, but does nothing to the axes' handle. You can check if anything has been drawn in the axes with:

cs = get(handles.axes1, 'Children');
if isempty(cs)
    % Nothing in axes
else
    % Something has been drawn in the axes

    if any(strcmp(get(cs, 'Type'), 'image'))
        % An image has been drawn in the axes
    end
end

You could also use findobj to the same effect,

hasImage = ~isempty(findobj('Type', 'image', 'Parent', handles.axes1));
wakjah
  • 4,541
  • 1
  • 18
  • 23