access a callback from a different m file

2 views (last 30 days)
Vincent I
Vincent I on 11 Jun 2013
Hi, I have two *.m file and to ease thing up and have less code in one of the m files I was wondering if I could access a callback in the other m file eg:
test1file.m
callback1
callback2
access callback2 in test2file.m
callback3
test2file.m
callback1
callback2
access this callback from callback2 in test1file.m
callback3
is this possible? I could copy the code from test2file.m callback2 but I'm trying to limit the amount of code.
Thank you
  1 Comment
Vincent I
Vincent I on 12 Jun 2013
Edited: Vincent I on 12 Jun 2013
"I would do like this (assuming you're using the GUI builder GUIDE).
Let's say that your figures/m-files are named firstFigure.fig/m and secondFigure.fig/m. In the code of firstFigure, just call secondFigure and pass your parameters as arguments:
someNumber = 1;
someText = 'test';
aMatrix = rand(3);
secondFigure(someNumber, someText, aMatrix);
The arguments will be available to secondFigure as a variable varargin in the callback functions
function varargout = secondFigure(varargin) and
function secondFigure_OpeningFcn(hObject, eventdata, handles, varargin)varagin is a cell structure; use cell2mat and char to convert it back:
theNumber = cell2mat(varargin(1));
theText = char(varargin(2));
theTextAgain = cell2mat(varargin(2));
theMatrix = cell2mat(varargin(3));"

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!