f



Call C code from Matlab -> Matlab crash

Hello,

I have a problem calling C code from Matlab. The mex file compilation
is ok. When I run the program Matlab (7.3) crashes. Below is the
mexFunction code. Any idea is welcome. (I think the main part of the
code (middle part) is not useful for the crash problem, but I put it
anyway).

//###########################################################
#include "math.h"
#include "mex.h"

void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[]) {
  // Standard variables
  int p,r,h,i,j,f,w; // Indices for loop
  int MAX_NBM = 1000;
  int MAX_DIM = 10;
  int MAX_NB_CLUST = 20;
  double *SF, *km, *new_data;
  int size, dim, K, nbm, aux_size, count_bis, count_aux;
  double diam_max, diam, vec1_p, vec2_p, dist_min, dis;
  int combi[1000000][2];
  int dist_aux[1000000][2];

  /* Check for proper number of arguments. */
  if (nrhs != 5) {
    mexErrMsgTxt("5 input required.");
  } else if (nlhs > 1) {
    mexErrMsgTxt("Too many output arguments");
  }

  // Input parameter (MATLAB)
  new_data = mxGetPr(prhs[0]);
  size = (int)mxGetScalar(prhs[1]);
  dim = (int)mxGetScalar(prhs[2]);
  K = (int)mxGetScalar(prhs[3]);
  km = mxGetPr(prhs[4]);
  
  // Output parameter (MATLAB)
  plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
  SF = mxGetPr(plhs[0]);
  
  // Other variables
  nbm = size/dim; // Number of points
  printf("Taille: %d\n",nbm);
  printf("Dimension: %d\n",dim);
    
  //###############################################
  // Calculate diameter of all clusters
  //###############################################
  diam_max = 0;
  for (p=1; p<=K; p++) {
    double current_clust_mat[1000*10];
    int counter = 0;
    
    // Group points belonging to the same cluster
    for (r=0; r<nbm; r++) {
      if (km[r] == p) {
	// Fill the array with the current point
	for (h=0;h<dim;h++) {
	 //printf("%d %d\n",counter*dim+h,new_data[r*dim+h]);
	 current_clust_mat[counter*dim+h] = new_data[r*dim+h];
	}
	counter++;
      }
    }
    
    // Calculate maximum distance (diameter of cluster)
    aux_size = counter;
    //printf("%d\n",aux_size);
    count_aux = 0;
    // Find combination of 2 in aux_size
    for (i=1; i<aux_size; i++) {
      for (r=i+1; r<aux_size+1; r++) {
	combi[count_aux][0] = i;
	combi[count_aux][1] = r;
	//printf("%d %d\n",combi[count_aux][0],combi[count_aux][1]);
	count_aux++;
      }
    }

    // Distance between two vectors
    diam = 0;
    vec1_p = 0;
    vec2_p = 0;
    for (h=0; h<count_aux; h++) {
      double dist = 0;
      for (j=0; j<dim; j++) {
	vec1_p = current_clust_mat[combi[h][0]*dim+j];
	vec2_p = current_clust_mat[combi[h][1]*dim+j];
	//printf("%d\n",vec1[j]);
	// Standard Euclidean distance
	dist = dist + (vec1_p-vec2_p)*(vec1_p-vec2_p);
      }
      dist = sqrt(dist);
      //printf("%f\n",dist);
      if (dist > diam) {
	diam = dist;
      }
    }
    
    // Maximum diameter of all clusters
    if (diam > diam_max) {
      diam_max = diam;
      printf("Diameter max: %f\n",diam_max);
    }
  }

  //##############################################
  // Calculate dissimilarity
  //##############################################
  dist_min = 1000000;
  // Find combination of 2 in nbm
  count_bis = 0;
  for (i=1; i<nbm; i++) {
    for (r=i+1; r<nbm+1; r++) {
      dist_aux[count_bis][0] = i;
      dist_aux[count_bis][1] = r;
      //printf("%d
%d\n",dist_aux[count_bis][0],dist_aux[count_bis][1]);
      count_bis++;
    }
  }
  
  // Dissimilarity
  dis = 0;
  vec1_p = 0;
  vec2_p = 0;
  //printf("\n");
  for (w=0; w<count_bis; w++) {
    // Cluster appartenance
    int clu1 = km[dist_aux[w][0]-1];
    int clu2 = km[dist_aux[w][1]-1];
    //printf("%d %d\n",clu1,clu2);
    
    // Calculate distance if belong to different clusters
    if (clu1 != clu2) {
      for (j=0; j<dim; j++) {
	// Vectors
	vec1_p = new_data[dist
0
9/27/2006 9:56:35 AM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
830 Views

Similar Articles

[PageSpeed] 2

Reply:

Similar Artilces:

methods to call matlab in C C++ and call C C++ in matlab
Hi, I am reading the help documents about how to program matlab and C C++ together and my questions are a little bit general. It seems that are several ways to call matlab in C C++ and another several ways to call C C++ in matlab. Please correct me if I am wrong or missing something when I try to list them. To call matlab code in C C++, are there two methods available? The first one is Matlab engine and the second one is to use MATLAB Compiler mcc to create C or C++ shared libraries from your MATLAB code. To call C C++ in matlab, are there also two methods? The first one is to call funct...

Calling Matlab in C in Matlab
Hi everybody! My problem can be described as follows. I have a tool in Matlab that requires calling an optimisation algorithm in C. This algorithm consists of several C-files, one of which contains the function to be minimised (CFUNCTION), and another is the main algorithm file (CMAIN). Now what I want to do is to call Matlab from CFUNCTION or CMAIN and specify my custom function (MFUNCTION) to be minimised. So, I'm calling Matlab from C from Matlab. I'm a newbie in C and MEX files. Should I rewrite CMAIN as a MEX file and include CFUNCTION in this and then use mxCallMATLAB? Or can...

matlab beginner: calling matlab from C/C++
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help On Nov 28, 10:03 am, "Paeo Campigotto" <campigo...@dit.unitn.it> wrote: > I'm relatively new to the world of Matlab. > I want to call my matlab own code from a C/C++ program on a > machine with matlab installed. > Do I need to compile the matlab code using matlab compiler > tool or the matla...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

matlab beginner: calling matlab from C/C++ #2
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help ...

matlab beginner: calling matlab from C/C++ #3
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help ...

MATLAB algorithm to MATLAB function code or C code
hallo firends, Can any body help me write this below code into MATLAB object oriented code or C code form please? M=50; % total number of periods. (choose for 1s duration) f0 = 50; % fundamental AC frequency T0 = 1/f0; %fundamental AC period T = M*T0; %Time for M periods (integer M) N=30; % sample points per period. dt = T0/N; % Sample at N points per period (integer N > 20) t = dt*[1:M*N-1]; % Sampling time array A0=120/2; % amplitude of AC signal. Divide by 2 or maybe sqrt (2) ? AC=A0*sin(f0*t*2*pi); % create AC signal. DC0=50; % DC amplitude DC=DC0*ones(1,length(t)); % create a DC signal that is constant of length t S=AC+DC; % total signal is AC signal + DC signal figure(1); plot(t,S); % plot signal. xlabel('time');ylabel('Signal'); title('Total Signal'); % filter components fAC=S-mean(S); % here is the AC component fDC=mean(S); % here is the DC component figure(2); plot(t,fAC,'r',t,fDC,'b'); % plot AC and DC signals legend('AC','DC'); xlabel('time');ylabel('Signal'); title('Signal with only AC component'); figure(3); plot(t,fDC,'b'); % plot DC signal legend('DC'); xlabel('time');ylabel('Signal'); title('Signal with only DC component'); figure(4); % best to plot in Fourier domain u=abs(fftshift(fft(S))); NumPoints=length(t); freq=(1/dt)*[1:NumPoints]/NumPoints; % create frequency axis freq=fre...

calling Matlab code from C/C++ code
Hi, I am learning to call Matlab code from C/C++ code. Here are my questions (1)are using Matlab engine and converting Matlab code into a C or C++ shared library the only two ways? (2) what's the difference between these two methods? Advantages and disadvantages? In what case use which method is better? Thanks and regards! On Mon, 03 Aug 2009 10:33:00 -0400, Tim <timlee126@yahoo.com> wrote: > Hi, > I am learning to call Matlab code from C/C++ code. Here are my > questions > > (1)are using Matlab engine and converting Matlab code into a C or C++ > shared library...

converting c++ code to Matlab code using Matlab 9
im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these codes in my project rather than writing them from scratch. is there some way or a chunk of code that might convert C++ code to matlab code or a ".c" file to ".m" file. please if anyone knows do let me know at the earliest.thanks "fatima " <fatima_naseem2002@yahoo.com> wrote in message <i8ugqn$e9p$1@fred.mathworks.com>... > im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these c...

calling matlab code from Visual Studio & converting standard c types to matlab
Hiya, I'm writing c language code & I'd like to be able to integrate a number of matlab functions to my code. I've tried to do this with the visual studio add in, but it always generates errors. I'm able to compile c code with the matlab compiler, but whenever I try to call a matlab function this causes errors. How does one compile c++ code with matlab? And when I'm at it, how can standard c variable types(int, double...) be converted to matlab types (and in the opposite direstion too)? Thanks for your help ...

How to call matlab functions directly from C++ /without calling matlab engine
How to call matlab functions directly from C++ without calling matlab engine. as it is described in this tutorial: http://www.codeproject.com/samples/matlab_cpp.asp I have tried to do something similar in Visual Studio 2005 [Matlab 7, r14] #include <mclcppclass.h> .... mwArray A, B, C; A = magic(mwArray(5)); B = transpose(A); .... but it doesn't compile. I got following errors: error C3861: 'magic': identifier not found error C3861: 'transpose': identifier not found etc... I was looking for header files with declarations of this functions in matlab directory...

EngSim: All Matlab features and functions. 2 to 20 Times Faster than MATLAB. Use the same programming syntax as MATLAB, ANSI C/C++, /C++. Good Graphics.
ENGSIM is an Engineering Simulation & Graphics Library for Microsoft Visual C++. It has all Matlab features and functions. 2 to 20 Times Faster than MATLAB. Very Easy to program. Use the same programming syntax as MATLAB, ANSI C/C++. Graphics Support is Very Good. Support Negative Indexing for Array/Matrix, Complex Array and Complex Matrix. Support Fix-point/Floating-point Communications Engineering and Signal Processing Simulation. Support Statistical Analysis. Support User- Defined Classes. Support User-Graphics Development ...

Converting Matlab code to C using Matlab Compiler
Hello All, Please can I get some guidance on how to Convert a structure from Matlab code to C code using Matlab Compiler. Kind regards Sammy ...

Calling Compiled MATLAB from MATLAB
Hello everyone, How do I compile MATLAB M files into a form that can then be called from within the MATLAB interpreter? A roundabout way would seem to be to (somehow) Turn the matlab code into C (I think mcc does this), then compile this C code into MEX format and call that. Is there an easier way? I have the MATLAB compiler, so I just need to know what to do with it to get this to work. Thanks in advance, Sina sina.tootoonian wrote: > > > Hello everyone, > > How do I compile MATLAB M files into a form that can then be called > from within the MATLAB interpreter? A roundabout way would seem to > be > to (somehow) Turn the matlab code into C (I think mcc does this), > then > compile this C code into MEX format and call that. Is there an > easier > way? I have the MATLAB compiler, so I just need to know what to do > with > it to get this to work. > > Thanks in advance, > > Sina > > HELP MEX > HELP MEX Or, better, HELP MCC help pcode pseudo code is useful to obfuscate code - protect algorithms, yet still run at full speed and be distributable to other matlab users sina.tootoonian wrote: > > > Hello everyone, > > How do I compile MATLAB M files into a form that can then be called > from within the MATLAB interpreter? A roundabout way would seem to > be > to (somehow) Turn the matlab code into C (I think mcc does this), > then > compile this C code into MEX format and call that...

vectorized computation in C++ such as those in Matlab (Matlab to C++)?
Dear all, Can C++/STL/Boost do the vectorized calculation as those in Matlab? For example, in the following code, what I really want to do is to send in a vector of u's. All other parameters such as t, l1, l2, l3, etc. are scalars... But u is a vector. Thus, t6 becomes a vector. t9 is an element-wise multiplication... The following code was actually converted from Matlab. If vectorized computation is not facilitated, then I have to call this function millions of times. But if vectorized computation is okay, then I can send in just a u vector with batch elements a time. I have man...

MathWorks Webinar: MATLAB to C Code Generation with Embedded MATLAB
Join Houman Zarrinkoub, PhD on March 11th for two Live Webinar sessions: 9am U.S. EST- http://bit.ly/bxcQuw 2pm U.S. EST- http://bit.ly/9g7Oqe In this webinar we will showcase new capabilities of MathWorks products enabling you to automatically generate C code from MATLAB functions. This capability is available for a subset of MATLAB language called the Embedded MATLAB. This subset consists of over 300 MATLAB operators and functions and more than 110 Fixed-Point Toolbox and 40 Signal Processing Toolbox functions and new system objects from Signal Processing and Video and Image Processin...

Shall i use the misrosoft Visual c++ code from a m-file generated from matlab in Visual C++ with out matlab runtime environment
undefined ...

mex - matlab calls fortran which calls matlab which calls fortran
Dear All, I'm trying to link matlab and fortran with mex files and engine matlab, in linux OS. My general purpose is the following: 1) a matlab script A calls a mex function B based upon fortran source code 2) mex function B calls another function in matlab C within matlab engine 3) matlab routine C calls another mex file in fortran D While i'm able to do steps 2) and 3), I can't do step 1). Before to show the code, please reply to this simple question: Is it possible to build the overall process 1-3? On 8 Okt, 16:37, "Michele Catalano" <cata...@yahoo.it> wr...

Conversion from MATLAB to C/C++ using MATLAB compiler
I am working on conversion of .m files to c/c++. I am using the MATLAB compiler version 3.0 and MATLAB version 6.5.1. There seem to be a few functions which do not seem to get converted. The error i got while using functions like TRAIN, NETWORK and INIT (all neural-networks related functions used in the general neural network programs, newpnn.m etc) is The MATLAB compiler does not currently support MATLAB object oriented programming and the functions TRAIN , NETWORK and INIT would produce a run-time error. Could anyone please tell me as to how i can circumnavigate this problem or solve this...

Calling matlab from java (windows), and running the java code not using the matlab JVM
Hello, I want to know if there is a way to call matlab from java (in windows), but not by calling the java code from matlab. I want to use a different JVM than the one matlab uses. In linux it is simple since I can use input/output redirection, is there a way to do this in windows (I have matlab 5.3, pretty old version). Thanks a lot, Nili. ...

Calling C++ Code in Matlab
Hello I want to Call C++ Code Multiple times in my Matlab code, My C++ Code ask for two comand line input argument. where this two command line input argument are Input file name and output file name. I am working in ubuntu operating System and and Matlab 7.11.0 Please help me !!! My C++ Code is in Multiple file like graph.cpp graph.h main.cpp vertex.cpp vertex.h stack.h "Rajan " <rajanshrivastava9@gmail.com> wrote in message news:kcrp9a$gab$1@newscl01ah.mathworks.com... > Hello > > I want to Call C++ Code Multiple times in my Matlab code, My C...

Create (Matlab) object inside C/C++ and pass it to Matlab
I'm trying to create an object inside C++ and then pass it to Matlab via en= gPutVariable. It seems I can create a struct // Create a float array mxArray *acq_data =3D mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS); float *data =3D (float *)mxCalloc(M*N, sizeof(float)); mxSetData(acq_data, data); mxSetM(acq_data, M); mxSetN(acq_data, N); // Convert to struct const char *fieldname =3D "data"; mxArray *acq_struct =3D mxCreateStructMatrix(1,1,1, &fieldname); mxSetField(acq_struct,i,"data",acq_data); // Convert to class ?? Does it work? if (j=3D=3D1...

calling Matlab code in C#
Hi, In my project, I need to call a Matlab function in some C# code. I compiled the Matlab code into a dll and have included that into my C# project. However, I have some problems in figuring out what C# data types correspond to the data types I used in my Matlab code. Specifically, I have an array of struct in Matlab code, i.e. x(j) = c, and c is a struct, having c.a and c.b. I also have a multi-layer struct, something like lmcoords.goalyellow.left.x = -0.67; lmcoords.goalyellow.left.y = -3; lmcoords.goalyellow.right.x = 0.67; lmcoords.goalyellow.right.y = -3; Basically I want to find...

MATLAB talking to MATLAB?
For my project, I need to have a client program (MATLAB executable) talking to a server program (also MATLAB executable) to query data. Is there any easy way to accomplish that? I appreciate any help that I can get on that. Thanks. Cheers, Hoi Oops, I forgot to mention. There are multiple clients querying the server, so I guess serial objects + remote serial port wouldn't work. "Hoi Wong" <wonghoi.ee@gmail.com_> wrote in message news:f3ald6$gg4$1@news.Stanford.EDU... > For my project, I need to have a client program (MATLAB executable) > talking to a ser...

Can I call matlab linear symstem solver in fortran or c on the machine without matlab ?
Can I call matlab linear symstem solver in fortran or c on the machine without matlab ? I have a fortran code now.I need to solve a sparse linear system.Can I call matlab A\B in my programming on the machine without matlab?Thank you all. "zedong" > Can I call matlab A\B in my programming on the machine without matlab... no us "us " <us@neurol.unizh.ch> wrote in message <gn5p03$sho$1@fred.mathworks.com>... > "zedong" > > Can I call matlab A\B in my programming on the machine without matlab... > > no > us Is the \ for sparse matrices not available with the MATLAB Compiler? James Tursa "zedong " <zdongwu@gmail.com> wrote in message <gn5o21$r3l$1@fred.mathworks.com>... > Can I call matlab linear symstem solver in fortran or c on the machine without matlab ? > I have a fortran code now.I need to solve a sparse linear system.Can I call matlab A\B in my programming on the machine without matlab?Thank you all. Yes, effectively so. A\b in MATLAB uses UMFPACK, CHOLMOD, MA57, a sparse QR by John Gilbert, and other specialized solvers (such as handling the case when A is lower triangular, or when A is banded with a density in the band that's high enough to warrant the use of LAPACK's band solvers). Most of these codes are readily available. MA57 requires a license; it's in the Harwell Subroutine Library. I don't have a copy of Gilbert's sparse QR, but I do...

Web resources about - Call C code from Matlab -> Matlab crash - comp.soft-sys.matlab

Undocumented Matlab
Undocumented, unsupported and hidden features in Matlab

Matlab Upazila - Wikipedia, the free encyclopedia
... 23°21′N 90°42.5′E  /  23.35°N 90.7083°E  / 23.35; 90.7083 Coordinates : 23°21′N 90°42.5′E  /  23.35°N 90.7083°E  / 23.35; 90.7083 Matlab ...

Open Directory - Science: Math: Software: MATLAB
The MathWorks - Developers of MATLAB, Simulink and Stateflow. Offers products for data analysis, visualization, application development, simulation, ...

MATLAB Mobile on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about MATLAB Mobile. Download MATLAB Mobile and enjoy it on your iPhone, ...

The Smart Emergency Response System Using MATLAB and Simulink - YouTube
In the aftermath of an earthquake, every second counts for disaster victims. Imagine a system that can locate people quickly and help first responders ...

The A-Z of Programming Languages: MATLAB
What prompted the development of MATLAB?

Matlab: Invalid .NET Framework. Either the specified framework was not found or is not currently supported ...
If you are trying to compile Matlab into .Net framework, you might encounter this message, even though you have the .Net framework installed ...

Matlab edges closer to electronic design automation world
Matlab, one of the world's most widely used products for algorithmic development, has long occupied its own niche far removed from EDA and hardware ...

Can I/How do I use DMTCP with a parallel pool of MATLAB workers? · Issue #223 · dmtcp/dmtcp · GitHub
dmtcp - DMTCP: Distributed MultiThreaded CheckPointing matlab -nodisplay -r "parpool('local',4); parfor i=1:10, pause(1); fprintf('%i ',i); end; ...

Using MATLAB and SDR to Reverse Engineer 433MHz Messages
... so he focused on studying the methodology and the tools available for analyzing 433MHz RF transmission. He describes the process of using MATLAB ...

Resources last updated: 3/4/2016 11:31:36 AM