Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Save a function in Matlab figure

Subject: Save a function in Matlab figure

From: karenin

Date: 16 Dec, 2013 21:05:08

Message: 1 of 1

I wrote a function that displays two images on top of each other (see below). By clicking on the image, I toggle between the two. This works well, however if I save the figure as fig file and open it again, it only works if the below function is on the path. Is there a way of storing the code for the ButtonDownFcn directly in the figure? This may be useful if I want to send the figure files to somebody but do not want to send the function as well.

Thanks for any advice!
Henry


function figHandle = imageOverlayToggleFade(im1,im2)

figHandle = figure;
h1 = imshow(im1,[]); hold on, h2 = imshow(im2,[]);
set(h2,'ButtonDownFcn',@buttonPress)

end

function buttonPress(h,~)
alphaData = get(h,'alphadata');
if alphaData == 1
    set(h,'alphadata',0)
else
    set(h,'alphadata',1)
end
end

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us