MATLAB: Passing an axes handlle to a function

argumentaxesfunctionimage

I have created a function in which I want to be able to take an image from an axes1 component and redraw on another axes component…with this target axes component being passed as n argument. This is my attempt:
The function:
function rescaleImage(handles,str)
%Get image on axes1
axes(handles.axes1)
image1=getimage(handles.axes1);
%Create handle for new placement of image
%Use str argument to pass the axes handle.
str2func(str)
imshow(image1,[])
Calling the function to redraw the image onto axes3.
rescaleImage(handles,'handles.axes3')
There is no error message, but the image does not redraw on axes3.

Best Answer

function rescaleImage(handles,str)
%Get image on axes1
axes(handles.axes1)
image1 = getimage(handles.axes1);
%Create handle for new placement of image
%Use str argument to pass the axes handle
imshow(image1,[], 'Parent', handles.(str))
and instead of passing 'handles.axes3' pass 'axes3'