All posts tagged “Matlab

comments 2

Parallel Computing Toolbox code fails with Java Virtual Machine updates 1.6.0_39 and 1.7.0_13


Parallel Computing Toolbox code fails with Java Virtual Machine updates 1.6.0_39 and 1.7.0_13


Running any Parallel Computing Toolbox code using a Java Virtual Machine (JVM) version of 1.6.0_39 or 1.7.0_13 might cause a NullPointerException to be thrown by the JVM. For example:

>> matlabpool open
Error using matlabpool (line 134)
Java exception occurred:
at java.util.logging.Logger.demandLogger(
at java.util.logging.Logger.getLogger(

This is a bug in the JVM update, and affects all versions of Parallel Computing Toolbox. The patches below fix the issue for 3rd party clusters and the local cluster. There is a related issue with MJS clusters that is under ongoing investigation.


To work around this issue, follow these installation instructions.

Log in to an account with appropriate permissions to overwrite files in your MATLAB installation. On Linux systems, this is typically the root account.
Locate your MATLAB installation by typing matlabroot at the MATLAB command prompt. This folder is referred to as in subsequent steps.
Download the attached .zip file associated with this Bug Report and store the file in the folder.
Make a backup copy of each of the files listed in the .zip file. To see the contents of the .zip file:
Windows Systems*: Open the .zip file and look at the contents.
Linux/Macintosh Systems: Type the following in a shell (Linux) or in a terminal window (Macintosh):
unzip -l /<.zip file>
Extract the files from the .zip file.
Windows Systems*:
Open the .zip file.
Extract the contents of the file to your folder.
Linux/Macintosh Systems: Type the following in a shell (Linux) or in a terminal window (Macintosh):
unzip <.zip file>
Delete the .zip file in the folder.
*Notes for Windows systems:

If you see “Error: Access is denied” when attempting to extract the .zip file, you might need to start WinZip in administrator mode. Do this by navigating to WinZip.exe or the WinZip Start menu entry, right-clicking on it, and selecting Run as administrator.
From within WinZip, find and open the downloaded .zip file.
Extract the contents of the file to your folder.
Change log:

February 21, 2013:

Digiprove sealCopyright secured by Digiprove © 2013
comment 0

matlab C api 사용시 mclmcrInitialize_proxy 에러가 발생할 때.

Technical Solutions

Why do I receive a linking error about
mclInitializeApplication_proxy and mclmcrInitialize_proxy when I compile
my driver application that calls a C++ shared library compiled using
MATLAB Compiler 4.10 (R2009a)?

Date Last Modified: Thursday, July 30, 2009

Solution ID:   1-AB2V2G
Product:   MATLAB
Reported in Release:   R2009a
Platform:   All Platforms
Operating System:   All OS



Why do I receive a linking error about
mclInitializeApplication_proxy and mclmcrInitialize_proxy when I compile
my driver application that calls a C++ shared library compiled using
MATLAB Compiler 4.10 (R2009a)?

Problem Description:

I have written a MATLAB function called mytest.m that is defined
as follows:

function result = mytest(V)
result = sum(sum(V));

I am compiling this into a DLL using the MCC command using MATLAB
Compiler 4.10 (R2009a) as follows:

mcc -W cpplib:Test -T link:lib mytest.m -v

Then I write a driver application called mydriver.cpp (see below), which
when compiled with the following command

mbuild mydriver.cpp Test.lib

gives me the error:

mydriver.cpp(7) : error C3861: ‘mclInitializeApplication_proxy’:
identifier not found
mydriver.cpp(51) : error C3861:
‘mclmcrInitialize_proxy’: identifier not found

C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Compile of ‘mydriver.cpp’

However, when I compile the same application using MATLAB Compiler
4.7 (R2007b), the compilation completes successfully.


This error may occur only with MATLAB Compiler 4.8 (R2008a) or
later versions because of changes that have been introduced in
mclmcrrt.h and mclmcr.h, which impose the requirement that mclmcr.h
always be included after mclmcrrt.h for the pre-processing stage.

the attached driver application, the following code is found on Lines

#include "mclcppclass.h"
#include "Test.h"

Here, mclcppclass.h (found in the <matlabroot>/extern/include
directory) in turn includes mclmcr.h.

Also, in the generated
Test.h file, the following code can be found:

#include "mclmcrrt.h"
#include "mclcppclass.h"

This results in mclcppclass.h being included before mclmcrrt.h, thus
causing a symbol resolution issue for the identifiers
mclInitializeApplication_proxy and mclmcrInitialize_proxy.

order to resolve this issue, change the order of the header files in
mydriver.cpp to the following:

#include "Test.h"
#include "mclcppclass.h"

Also, since Test.h already includes mclcppclass.h, you can entirely
avoid including this header file in your driver application.

Filed under: Uncategorized
comment 0

MATLAB Shared Library using dll

Sample screenshot - 
Matlab Shared Library


Some times it is
required that we build a shared library (DLL) from an m-file. M-files
are functions that are written in Matlab editor and can be used from
Matlab command prompt. In m-files, we employ Matlab built-in functions
or toolbox functions to compute something. In my past articles, I showed
you some ways to use Matlab engine (vis. API, C++ class or Matlab
engine API) for employing Matlab built-in functions, but what about
functions that we develop? How can we use them in VC? Is there any
interface? This article shows you an idea to employ your own Matlab

Shared Libraries

Shared libraries or DLLs are
files that export some functions. We can use exported functions in any
language. Here is a brief instruction to build shared libraries from
Matlab m-files:

  1. Compile your m-file into a DLL (from Matlab
    command prompt):

    mcc -t -L C -W lib:mylib -T link:lib -h <M-file> libmmfile.mlib

    -t option tells the Matlab compiler to translate the m-file to the
    target language. The -L option specifies the target language, which is
    chosen to be C. The -W option tells the Matlab compiler to build a
    wrapper for the library with the name specified by “lib:”. The -T option
    tells the compiler what stage should be reached and for what
    intentions. Here we link our application together to build a shared
    library (DLL). Specifying libmmfile.mlib tells Matlab compiler to
    link against Matlab m-file math routine.

    This step will produce mylib.dll,
    mylib.lib and mylib.h. For debugging purposes, you can
    add the -g switch to produce a DLL suitable for debugging in MSVC.

    example, I wrote my own mean function and saved it as MeanFunction.m:

    function y=MeanFunction(x)[m,n]=size(x);k=0;for i=1:n    k=k+x(i);endy=k/n;

    compiled it with mcc:

    mcc -t -L C -W lib:MeanFunctionLib -T link:lib MeanFunction.m libmmfile.mlib
  2. Create
    your project in VC. In your main CPP file, include your function header
    file and add the related library. Here I create a simple console
    application. Make sure to call initialization and termination routines
    from your code before and after of calling the m-file function.

    #include "stdafx.h"#include "matlab.h"#include "MeanFunctionLib.h"#pragma comment(lib, "libmx.lib")#pragma comment(lib, "libmatlb.lib")#pragma comment(lib, "libmat.lib")#pragma comment(lib, "libmmfile.lib")#pragma comment(lib, "MeanFunctionLib.lib")int main(int argc, char* argv[]){    mxArray* result;    mxArray* x;    double myArray[5]={10.2, 3, 6.3, 5.4, 5.9};        x=mxCreateDoubleMatrix(1, 5, mxREAL);    memcpy(mxGetPr(x), myArray, 5 * sizeof(double));    MeanFunctionLibInitialize();    result=mlfMeanfunction(x);        MeanFunctionLibTerminate();    mlfPrintMatrix(result);    mxDestroyArray(x);    mxDestroyArray(result);    return 0;}
  3. Build
    your project.

Notice that you must use Matlab C API or
Matlab C++ class library to use mxArray or mwArray. For more information, refer to my articles:



This article has no explicit license attached
to it but may contain usage terms in the article text or the download
files themselves. If in doubt please contact the author via the
discussion board below.

A list of licenses authors might use can
be found here

the Author


was born in Shiraz,
a very beautiful famous city in Iran. I started programming when I was
12 years old with GWBASIC. Since now, I worked with various programming
languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and
now Visual C++.
I graduated from Iran
University of Science & Technology
in Communication Eng., and
now work as a system programmer for a telecommunication industry.
wrote several programs and drivers for Synthesizers, Power Amplifiers,
GPIB, GPS devices, Radio cards, Data Acqusition cards and so many
related devices.
I’m author of several books like Learning C (primary
and advanced), Learning Visual Basic, API application for VB, Teach
Yourself Object Oriented Programming (OOP) and etc.
I’m winner of
January, May, August 2003 and April 2005 best article of month
competetion, my articles are:

Filed under: Uncategorized
comment 0

Matlab Compiler problems in Windows(x64)

Notes for the Windows (64-bit) Platform

  1.  You must install a C compiler to use LOADLIBRARY on a 64-bit platform.
  2.  Intel compilers depend on tools provided by Microsoft development products. Support for Intel compilers requires Microsoft Visual Studio 2005 SP1 Professional Edition. Access to the 2005 SP1 edition is available from Microsoft as part of their Visual Studio with MSDN subscriptions.
  3.  These compilers are being phased out and will not be supported in a future release.
  4. To build .NET components, Microsoft .NET Framework 2.0 must be installed. This product is automatically installed by Visual Studio 2005 or 2008. It can also be downloaded from the Microsoft Web site. To execute applications that use the resulting .NET components, the target machine must have the matching .NET Framework installed.
  5.  MATLAB Builder NE supports building .NET Assemblies but not COM objects when using the Microsoft .NET Framework SDK without Microsoft Visual Studio.
  6. To use Microsoft Visual Studio with MATLAB on a 64-bit platform, you must choose “X64 Compilers and Tools” when installing Microsoft Visual Studio. This is not selected by default. Microsoft Visual Studio 2008 Express and Professional Editions also require that the the Microsoft Windows Software Development Kit (SDK) is installed properly. For more information, see Solution 1-6IJJ3L.
  7.  Includes Real-Time Workshop Embedded Coder and Stateflow Coder compiler support.
  8. Fortran compilers are supported with Simulink only for creating Simulink S-functions using the MATLAB MEX command. The S-functions can be used with normal and accelerated simulations.

from :

when you stucked on error code 53 with mbuild, mex or mcc, check these.

Filed under: Uncategorized
comment 0

[MATLAB] Labeling labeled objects

A post in comp.soft-sys.matlab this week (see the third post in this thread) asked how to display graphically the numerical labels associated with each labeled object. In this blog I’ll show a couple
of ways to approach that task.

First, let’s back up a bit. We’re talking about labeling connected groups of pixels in binary images. Here’s an example,
starting with the grayscale image coins.png.

I = imread('coins.png');

Threshold to form a binary image.

bw = im2bw(I, graythresh(I));

Fill in the holes.

bw2 = imfill(bw, 'holes');

You can easily see that there are 10 objects in the image. But to start doing geometric measurements, we have to be able
to identify which foreground pixels belong to which object. That’s what bwlabel does.

L = bwlabel(bw2);

L is a label matrix. It’s the same size as bw2.
It contains the value 0 in each location that’s a background pixel. It
contains positive integer values in locations corresponding to a
labeled foreground object. For example, to see the eighth object, you
just determine all the elements of L that equal 8:

imshow(L == 8)
title('Object 8')

back to the original question – How can we graphically display each
object’s label? One way is to compute the centroid of each object, and
then superimpose text strings on top of the image at the centroid
locations. Here’s one implementation:

s = regionprops(L, 'Centroid');
hold on
for k = 1:numel(s)
c = s(k).Centroid;
text(c(1), c(2), sprintf('%d', k), ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle');
hold off

My second method is more interactive. It uses a fairly new MATLAB feature: Data cursors.

If you haven’t seen MATLAB data cursors before, here’s a screen shot showing what happens when you click on a plot in data
cursor mode.

Data cursors work for images, too:

With a modest bit of programming (see Customizing Data Cursor Text), you can customize the data cursor strings. Here, we just want the object label to be displayed. I wrote a little function
called display_label_matrix that does just that. It’s just a dozen lines of code. Here’s what it looks like for the coins example:

And here’s the code:

type display_label_matrix
function display_label_matrix(L)
% display_label_matrix Display label matrix with custom data cursors
% display_label_matrix(L) displays the label matrix L as colored objects on
% a gray background. It also installs a custom data cursor handler in the
% figure. In data cursor mode, clicking on an object displays a data
% cursor containing the object's number.

% Steve Eddins
% Copyright 2006 The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 2006/11/17 19:11:30 $

rgb = label2rgb(L, 'jet', [.7 .7 .7], 'shuffle');
h = imshow(rgb);

% Store the label matrix so that the custom data cursor function has access
% to it.
setappdata(h, 'LabelMatrix', L);

% Enable the figure data cursor mode, and use our own custom data cursor
% strings.
dcm = datacursormode(ancestor(h, 'figure'));
set(dcm,'Enable','on', ...
'Updatefcn', @dataCursorText);

function output_text = dataCursorText(obj, event_obj)
% Respond to a user click in data cursor mode by displaying the label
% number of the pixel that was clicked on.

h_image = get(event_obj, 'Target');
pos = get(event_obj, 'Position');
L = getappdata(h_image, 'LabelMatrix');
clicked_label = L(round(pos(2)), round(pos(1)));
output_text = sprintf('%d', clicked_label);

Give it a try and let me know what you think.

Filed under: Uncategorized