access a callback from a different m file

2 visualizaciones (últimos 30 días)
Vincent I
Vincent I el 11 de Jun. de 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 comentario
Vincent I
Vincent I el 12 de Jun. de 2013
Editada: Vincent I el 12 de Jun. de 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));"

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by