-1

I have a Matlab application that has GUI in it. I am now trying to automate some operations and i need to call a function right after the GUI loads without any human in the loop. (Basically simulating human button clicks...)

I have tried calling the wanted function from "_OpeningFcn" and from "_OutputFcn" with no success.

I also tried to follow this link, yet it doesn't work as well :( http://www.mathworks.com/matlabcentral/answers/161545-call-callback-without-mmouse

Any other ideas to how i can invoke a function programmaticly after GUI is fully loaded?

THanks!

Edit1: AS i understood, if i want to call the function then i should bot it in "EnergyData_OutputFcn". so, here is what it looks like:

function varargout = EnergyData_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

hGuiFig = findobj('Tag','btnReportGeneration');
EnergyData('btnReportGeneration_Callback',handles.btnReportGeneration,[],handles);
varargout{1} = handles.output;

the thing is that this function is called recursively (i can see it when debugging) and i eventually get this error message:

Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit.  Be aware that exceeding your available stack space
can
crash MATLAB and/or your computer.

Error in genvarname>isCellString

That brings me to the question that assuming the method described in the post i attached in link above is the correct way, Where do i place this code? (I couldn't even find it in the example files he attached to the post...)

THANKS FOR THE HELP!

Eitan Vesely
  • 125
  • 3
  • 16
  • How exactly did you try what's posted in the link? It worked quite well for me. Can you post your codes? – user3667217 Sep 17 '15 at 22:12
  • THanksThese are the two lines i added: hGuiFig = findobj('Tag','btnReportGeneration') ; EnergyData('btnReportGeneration_Callback',handles.btnReportGeneration,[],handles) – Eitan Vesely Sep 18 '15 at 06:07
  • Do you mind putting these codes in your original post and describe what kind of error you encountered after you tried calling the GUI? – user3667217 Sep 18 '15 at 07:05
  • OK, I now got it. im calling it from an external script, WOrking like a charm :) – Eitan Vesely Sep 19 '15 at 09:21

1 Answers1

0

When automatically created with guide, you should have this part in your GUI code ? (you can create a simple GUI with guide and figure out where does it go otherwise)

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @V2Gsim_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @V2Gsim_gui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT 

Then calling on (in my case)

function V2Gsim_gui_OpeningFcn(hObject, eventdata, handles, varargin)

You can launch any function even before the GUI is opened.

  • How does this answer the question? You've just copy/pasted the pregenerated GUIDE code. – sco1 Sep 18 '15 at 12:20