TheGrapeBeyond
TheGrapeBeyond

Reputation: 563

How to return values from an inline function in MATLAB?

I have the following script:

im = imagesc(anImage, 'parent', gca); 
set(im,'HitTest','off');
set(gca,'buttondownfcn', @someFunction)

My problem is that I want someFunction to return some values, but I am not sure how to do it in THIS particular scenario. It seems like the inline-ness is not letting me do this...

Thanks.

Upvotes: 0

Views: 103

Answers (1)

applesoup
applesoup

Reputation: 487

To make someFunction() set a value in your base workspace (I assume that is what you want to achieve), you can use the assignin() function.

An example for someFunction() that sets the variable axes_position to the the current axes' position is the following

function someFunction(hObject, event)
assignin('base', 'axes_position', get(hObject, 'Position'));

Have a look at the axis and figure properties pages in the MATLAB user guide on how to deal with user UI input in axes and figure controls (not enough reputation to add two more links).

However, you mention that you want to manipulate it in the next line of the program. If I understand correctly, this is what the guidata function is meant for: "store or retrieve UI data".

Upvotes: 1

Related Questions