Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert Matlab files to C++ ?

Status
Not open for further replies.

asha19800

Banned
Joined
Dec 22, 2007
Messages
24
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
0
C++ and Matlab

I want to run a simulation written both in C++ and Matlab.I have MS Visual Studio installed.
How can I run the program whose one file out of many file is written in C++

please guide me through.
 

C++ and Matlab

I am not clear what you want.
Do you want to call a MATLAB script inside your C++ code, you want to write a function in C++ (to speed up your program) and call it from MATLAB script?
the first one is pretty easy, search "MATLAB computation engine" in MATLAB help, it is very easy.
to do the second one (calling a C++ program inside MATLAB), if you use simulink, see S-function in Help.
If it is not your answer please provide more information on what you want.
 

    asha19800

    Points: 2
    Helpful Answer Positive Rating
Re: C++ and Matlab

I am sorry that I am new in working at same time with matlab and C++.
I have been given a code whose three files are written in matlab and one is in C++ and names are:

midresult.m
final.m
midfinal.cpp
midfinal.m

I cant recognize whether a matlab script is called from a C++ code OR
a in C++ program is written to speed up the program and it has to be called from matlab.

I dont know how to identify what is the purpose of writting in this way.my intuition says that in C++ program is written to speed up the program and it has to be called from matlab.

mhamed ,you can help me and I am waiting for your reply.

Thanking U.
 

C++ and Matlab

I am sorry I didnot get your question. Do you have problem with running those codes? if yes, it is because you should first compile .cpp file using mex command of MATLAB. try this:
mex midfinal.cpp
and then run your code. You can also change the compiler if you encounter any problem during compilation:
mex -setup
hope this works
 

    asha19800

    Points: 2
    Helpful Answer Positive Rating
Re: C++ and Matlab

Hi
I refer u to the attached document
 

    asha19800

    Points: 2
    Helpful Answer Positive Rating
Re: C++ and Matlab

I first used the command
mex -setup

and than

mex midfinal.cpp

and got the following error:



midfinal.cpp(142) : error C3861: 'copysign': identifier not found, even with argument-dependent lookup
midfinal.cpp(149) : error C3861: 'copysign': identifier not found, even with argument-dependent lookup
midfinal.cpp(156) : error C3861: 'copysign': identifier not found, even with argument-dependent lookup

C:\PROGRAM FILES\MATLAB\R2006A\BIN\MEX.PL: Error: Compile of 'midfinal.cpp' failed.

??? Error using ==> mex
Unable to complete successfully

any solution?

Added after 3 hours 17 minutes:

Thank you very much all of U as I have finally run the program.
The mistake was as follows:

As I am using MS Visual Studio,therefore when I executed the command
mex -setup
I was always given option to select on of the compiler as follows:

___________________________________________________________________
Select a compiler:

[1] Lcc C version 2.4.1 in C:\PROGRAM FILES\MATLAB\R2006A\sys\lcc
[2] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio .NET 2003
[3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio

[0] None

Compiler:
____________________________________________________________________

and in response I always used option [2] which did not work but now when I select lption [1] it works.
I dont know the reason for this but it works

Thanks s Lot.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top