Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create .exe via MCR results in error: ??? Error while evaluating uicontrol Callback

30 views
Skip to first unread message

MatlabUser Start

unread,
Feb 12, 2012, 4:45:10 PM2/12/12
to
Hi @ all,

I developped a GUI to analyze pictures and I wanted to create an executable file via MCR (Matlab Compiler Runtime). Unfortunally, I always get the following error:

??? Error while evaluating uicontrol Callback

I debugged the code and figured out that the error occurs while I call a self-written function. The function contains handles and a number as input arguments. I call it like

startframehuge(hObject, handles, 1)

I included also functions like VideoReader and guidata in the executable function because without VideoReader I get an error, too. Hence, I thought by including guidata, that this works out for the parameter hObject and handles again. But the problem remains. Does anybody have an idea? Hope you can help me.

Kind Regards

Sebastian

By the way: Is it necessary to add basic functions which are already implemented in Matlab (like VideoReader) to run an executable file? That would mean I have to insert min, max etc. too? Am I right?

ImageAnalyst

unread,
Feb 12, 2012, 8:19:22 PM2/12/12
to
MatlabUser Start / Sebastian
It is not necessary to add basic functions which are already
implemented in Matlab (like VideoReader) to run an executable file.
They will automatically be built into your executable. The only
things that aren't are things that have their own user interface, like
imtool.

Why are you doing this:
startframehuge(hObject, handles, 1)
? Where does it come from? Did one of your pushbutton callbacks call
that? Why are you passing hObject? I never do that - I never use
hObject. You know what the names of all the controls on your GUI are
called, so just call them by name when you need to get() or set() a
property of them. Just do this:
startframehuge(handles, 1);
You don't need hObject. Inside startframehuge you can call guidata,
or you can just pass back handles.
handles = startframehuge(handles, 1);
Either is required ONLY if you made changes to handles. If you never
called set() then you don't need to pass back handles or call guidata.

ImageAnalyst

MatlabUser Start

unread,
Feb 13, 2012, 4:24:09 AM2/13/12
to
Hi ImageAnalyst,

> It is not necessary to add basic functions which are already
> implemented in Matlab (like VideoReader) to run an executable file.

Ok, but while the executable is running, the Matlab error sound appears if I do not include VideoReader within the executable file. Nevertheless, the algorithm continues to work. Can this be neglected? Or do the programme really having a problem at this point? (I inserted msgboxes after each line to find the position where this problem appears.) The 'sound error' line looks like:

avivid = VideoReader(handles.avifilename);

So it seams that my algorithm always get a problem if I use handles.

> startframehuge(hObject, handles, 1)
> ? Where does it come from?

The program terminates, if I call the function startframehuge(hObject, handles, framenumber) within a pushbutton callback. (If you want to see the code, have a look below below, but as I told you; the call of the function terminates already the program) The function startframehuge read out a video frame (here first frame: framenumber = 1) and write it to the figure element of the GUI. Within the function I use the variable handles to store the filedate.

It was the first GUI, which I developped and I read somewhere, (do not ask me where), that it is usefull to update the GUI parameteres via guidata after each function to avoid a loss of handles. So, i did this.

> Either is required ONLY if you made changes to handles. If you never
> called set() then you don't need to pass back handles or call guidata.

But if I use set I have to pass hObject as well. Otherwise guidata will not work (error 'variable hObect unknown') If I use set() I have to update the handles via guidata. Hence hObject should be included in the function? Or am I wrong?.

Thanks for help

Sebastian

function browsePushbutton_Callback(hObject, eventdata, handles)

%...

global avivid;

[avifilename avifilepath] = uigetfile('*.avi','avi-video');
handles.avifilename = avifilename;
handles.avifilepath = avifilepath;
...
addpath(handles.avifilepath);
avivid = VideoReader(handles.avifilename);
set(handles.activex1,'URL',[handles.avifilepath handles.avifilename]);
...
startframehuge(hObject, handles, 1)
...

guidata(hObject, handles);


function startframehuge(hObject, handles, framenumber)

% Displays the first frame of the chosen avi-file.
%
%
% (c) Copyright Sebastian Dittmar

global avivid
global oneframe
hmsgbox=msgbox('2','ok','help');
uiwait(hmsgbox);
mov(framenumber).cdata = read(avivid, framenumber);
handles.firstframe = double(mov(framenumber).cdata(:,:,2));
oneframe = subplot('position',[0 0.05 1 0.9]);
imagesc(handles.firstframe);
hold on;
title(['Frame ' num2str(framenumber)]);
axis 'equal';
set(gca,'XTick',[]);
set(gca,'XTickLabel',[]);
set(gca,'YTick',[]);
set(gca,'YTickLabel',[]);
colormap 'gray';
hold off;
pause(0.1);
if(str2double(get(handles.numberframesEdit,'String'))~=1)
set(handles.actualframeText,'String',['Frame: ' num2str(framenumber)]);
else
set(handles.actualframeText,'String','');
end

guidata(hObject, handles);

Steven_Lord

unread,
Feb 13, 2012, 9:53:42 AM2/13/12
to


"MatlabUser Start" <sebastia...@imp.uni-erlangen.de> wrote in message
news:jh9bt6$fi5$1...@newscl01ah.mathworks.com...
> Hi @ all,
>
> I developped a GUI to analyze pictures and I wanted to create an
> executable file via MCR (Matlab Compiler Runtime). Unfortunally, I always
> get the following error:
>
> ??? Error while evaluating uicontrol Callback
>
> I debugged the code and figured out that the error occurs while I call a
> self-written function. The function contains handles and a number as input
> arguments. I call it like
> startframehuge(hObject, handles, 1)

See the second section on this page from the documentation for MATLAB
Compiler:

http://www.mathworks.com/help/toolbox/compiler/br2cqa0-2.html

*snip*

> By the way: Is it necessary to add basic functions which are already
> implemented in Matlab (like VideoReader) to run an executable file? That
> would mean I have to insert min, max etc. too? Am I right?

MATLAB Compiler does some dependency analysis on your code to determine what
needs to be included in the executable. If you instantiate a VideoReader
object in your code in such a way that MATLAB Compiler "knows" that you're
using that class, it should pick it up. If your code LOADs in a MAT-file
containing a VideoReader and does not give any indication in the code that
you're actually working with a VideoReader (by calling the constructor, for
instance) you would need to explicitly list that dependency.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

MatlabUser Start

unread,
Feb 13, 2012, 11:15:12 AM2/13/12
to
Thanks for replies, but I still need help.

> See the second section on this page from the documentation for MATLAB
> Compiler:
>
> http://www.mathworks.com/help/toolbox/compiler/br2cqa0-2.html

I found this page too. But, I could not deal with the provided information, because I created my GUI with GUIDE and so I do not call the callbacks of the pushbutton. Pushbutton's and other callbacks of the GUI were created automatically. Hence, the ideas at the above mentioned link can not be used, or could they? Or with other words: Do I have to create the buttons with uicontrol as shown in the link to call callbacks with 'string' variables? +
Can you offer me an example how I can deal with the information? Or explain it step by step in easy words. Thanks ones more.

Kind Regards

Sebastian

PS: I do not have .mat files. I only have m-files.

MatlabUser Start

unread,
Feb 15, 2012, 5:14:11 PM2/15/12
to
Hi @ all,

I know now, why my code is not running. I use commands like 'addpath' and global variables. But both things are forbidden. See the following link:

http://blogs.mathworks.com/loren/2008/06/19/writing-deployable-code/

So I have a last question. Is their a workaround to use 'cd' and 'addpath' within MCR environment? Within the link, their is written the following statement. Please clarifexplain me the hint of the last line. Thanks in advance.

"Don't rely on the current directory (cd) or changes to the MATLAB path (addpath) to control the execution of M-files. The path of a deployed application is determined at compiled time, and remains forever fixed. The current directory is never on the path in a deployed application. In the code below, cd-ing to the stringFcns directory does not make stringFcns/add shadow mathFcns/add. The order of these functions at runtime depends on what their order was at compile time. This causes errors:

cd mathFcns
z = add(x, y);
cd ../stringFcns
s = add(s1, s2);

Avoid this problem by either using different function names, e.g., addstring and addnum or MATLAB Objects."

Kind Regards

Sebastian
0 new messages