0

I have a function called viewcsi(varargin) and I want to pass in three variables at most. The first is a MBSspectrum class I made and then a string and also a number.

viewcsi is a call back, it gets called like this:

...'ButtonDownFcn','viewcsi(''pickvox_cb'', sp_viewcsi)');

sp_viewcsi is the MBSspectrum class I made and is in the workspace. I want to be able to add another argument called counter which is integer of type double.

I want to do something like this:

...'ButtonDownFcn','viewcsi(''pickvox_cb'', sp_viewcsi, counter)');

or

...'ButtonDownFcn', {@viewcsi, 'pickvox_cb', 'sp_viewcsi', counter)');

But when I do the last two thing these do not work since they do not preserve 'sp_viewcsi' as a class but treats it like a string. What can I do to fix this? I have a feeling its something easy but I havent been able to figure it out.

2
  • 2
    Without seeing more code, or better yet a minimal example, it's hard to say, but this related question might help. Commented Oct 23, 2012 at 20:54
  • Yes more source code is needed but I was able to figure it out. Commented Oct 23, 2012 at 23:41

1 Answer 1

1

The ButtonDownFcn will only ever pass it two arguments. You can cheat it by saying

...'ButtonDownFcn',@(a,b)viewcsi(a,b, counter));

so that the callback will pass it a and b, while Matlab will hand it the current value of counter.

See also the doc on passing extra parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.