access a callback from a different m file

2 visualizzazioni (ultimi 30 giorni)
Vincent I
Vincent I il 11 Giu 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 Commento
Vincent I
Vincent I il 12 Giu 2013
Modificato: Vincent I il 12 Giu 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));"

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by