Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling Matlab From C

Posted on 2004-10-28
9
Medium Priority
?
616 Views
Last Modified: 2007-12-19
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
Comment
Question by:hssuma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 

Author Comment

by:hssuma
ID: 12431618
I have seen this link but somehow i'm getting lot of linking errors...
0
 
LVL 5

Expert Comment

by:van_dy
ID: 12431631
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:Sadrul
ID: 12435500
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
 

Author Comment

by:hssuma
ID: 12490802
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
 
LVL 2

Expert Comment

by:Sadrul
ID: 12494326
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
 

Author Comment

by:hssuma
ID: 12502272
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
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 13114950
PAQed with points refunded (50)

PAQ_Man
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question