access a callback from a different m file

2 Ansichten (letzte 30 Tage)
Vincent I
Vincent I am 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 Kommentar
Vincent I
Vincent I am 12 Jun. 2013
Bearbeitet: Vincent I am 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));"

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by