MATLAB Answers

Ria3242
0

Handling axes as arguments

Asked by Ria3242
on 4 May 2016
Latest activity Commented on by Mike Garrity
on 4 May 2016
Help needed...
In my GUI, there are 5 axes, one displays a grid of images, and the others display the cropped images from the grid having one cropped image from mouse input to be displayed on one axis in a sequence i.e. an image password of having four sub-images will be formed further. At first I was setting the new axis for the next cropped image by handling it in a loop. There were warnings regarding speed. Then I passed the handles in arguments as:
a2 = axes(handles.axes2);
a3 = axes(handles.axes3);
a4 = axes(handles.axes4);
a5= axes(handles.axes5);
before my loop started. and within the loop I ploted where I wanted:
switch password_count
case 0
plot (a2);
password_array(1)=temp_im; %#ok
case 1
plot (a3);
password_array(2)=temp_im; %#ok
case 2
plot (a4);
password_array(3)=temp_im; %#ok
case 3
plot (a5);
password_array(4)=temp_im; %#ok
end
now it gives me these errors:
Error using axes Too many output arguments.
Error in a2 = axes(handles.axes2);
Thanks in advance!

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Mike Garrity
on 4 May 2016

Axes only returns an axes handle in the cases where it is creating an axes object. The syntax where you pass an axes handle in is different. In that case, it's not creating an axes, it's just setting gca. It sounds like you probably want something like this instead.
axes(handles.axes2)
a2 = handles.axes;
Alternatively, you could skip the call to axes entirely. It looks like you're going to pass the axes handle into your plotting function. Therefore you really don't need to make it gca. But making it gca does have the nice side effect of making sure that the figure is in front of other windows.

  2 Comments

@Mike Garrity: it might be nice if axes returned the handle for all cases, even where it does not create a handle. Or is this special output case useful somehow?
Mike Garrity
on 4 May 2016
I'm afraid I don't know the history of that one. I'm afraid that it goes way, way back.
We have been on a bit of a kick of making things more uniform lately. Perhaps this one should be on the todo list.

Sign in to comment.