[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

Calling Matlab From C

Hello all,
 I have a C program running on Visual Studio 6.0. The output of the program is arrays say x[n] and y[n].. i need to plot a graph for n values.. So i have exported the array to matlab and there i plot it using plot command... So, to get the plots i need to first run the C program and then execute the matlab program to get the plots.. Is there any method so that i can get the plots directly by executing the C progam... To be more precise i mean calling the matlab program from C and executing it directly through C program... Please can u give me the procedure for doing so...
TIA
-Suma
0
hssuma
Asked:
hssuma
  • 3
  • 2
  • 2
  • +1
1 Solution
 
hssumaAuthor Commented:
I have seen this link but somehow i'm getting lot of linking errors...
0
 
van_dyCommented:
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
SadrulCommented:
you can give mcc a try: http://www-rohan.sdsu.edu/doc/matlab/toolbox/compiler/mcc.html

using mcc, you can generate c-code from matlab-code.

-- Adil
0
 
hssumaAuthor Commented:
I followed the instructions given in  http://www-rohan.sdsu.edu/doc/matlab/toolbox/compiler/mcc.html

but i'm getting few errors...

This is the program that i used..
#include<stdio.h>
#include<stdlib.h>
#include"engine.h"    
#include<string.h>
void main()
{
Engine *ep;
mxArray *mp, *ans;
double *ar, *detreal;
int i,j;
mp = mxCreateDoubleMatrix(3,3,0);
 mxSetName(mp,"A");
  ar = mxGetPr(mp);
   for( i =1;i<4;i++)

            {

 

                        for (j = 1;j<4;j++)

                        {

                                    ar[i-1+3*(j-1)] = j*j*i*i;

                        }

            }

 

ep = engOpen("");
engPutArray(ep,mp);
engEvalString(ep,"ans = det(A);");
ans = engGetArray(ep,"ans");
detreal = mxGetPr(ans);
fgetc(stdin);
printf("%d",deta[1]);
engClose(ep);

}

but i get errors like:::::::::::::

Compiling...
baffle.cpp
C:\work\baffle\baffle.cpp(11) : error C2664: 'mxCreateDoubleMatrix' : cannot convert parameter 3 from 'const int' to 'mxComplexity'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
C:\work\baffle\baffle.cpp(38) : error C2065: 'deta' : undeclared identifier
C:\work\baffle\baffle.cpp(38) : error C2109: subscript requires array or pointer type
Error executing cl.exe.

baffle.exe - 3 error(s), 0 warning(s)

Can u plzz help me solve it...
0
 
SadrulCommented:
we need to know the function prototype of  `mxCreateDoubleMatrix'. but looks like you can try:

mp = mxCreateDoubleMatrix(3,3, (mxComplexity)0);

the second/third errors, obviously you haven't declared a variable named `deta'. did you mean to use `detreal' here?

-- Adil
0
 
hssumaAuthor Commented:
Why doesn't this small program work???
I just want to see if my matlab engine is been able to open... It gives the linking errors.. i have included the libraries like giving the path i.e. MATLAB folder->extern->lib ->win32->Microsoft ->msvc6.0.

The code is::;


#include <stdio.h>
#include <stdlib.h>
#include"engine.h"    
#include<string.h>

int main()

{
   Engine *ep;
   mxArray *T = NULL, *result = NULL;
if (!(ep = engOpen("\0"))) {
      fprintf(stderr, "\nCan't start MATLAB engine\n");
      return EXIT_FAILURE;
   }
else
  printf("Success\n");
}

The errors encountered are

Linking...
begin.obj : error LNK2001: unresolved external symbol _engOpen
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/begin.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

begin.exe - 3 error(s), 0 warning(s)

Help me solve it..

0
 
PAQ_ManCommented:
PAQed with points refunded (50)

PAQ_Man
Community Support Moderator
0

Featured Post

Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now