Add your own alternative version
Stats
968.2K views 8.8K downloads 92 bookmarked
Posted
27 May 2003
Licenced

Comments and Discussions


I have succesfully run you demonstration program under Matlab 6.5.0, but have now been upgraded to 7.0.4 (R14 service pack 2), which casues missing header errors. In a previous message, you mentioned that matlab.h needed to be replaced with mclmcr.h for the files to run under Matlab 7. However, neither file exists in my current version. Do you know if the headers been changed yet again, and what is needed now?
Thanks,
James





In fact, neither "matlab.h" nor "matrix.h" is needed to run this demo in Matlab 7.0! Also, "libmatlb.lib" and "libmmfile.lib" should be removed.
Good luck.
Zhang





Hi,
I read your article with great interest and i was wondering if this works with a simulink model as well.
We want to use a control system diagram designed in simulink in a standalone VC++ (MS studio 6 or .NET 2005)
This system has several inputs and outputs and a lot of parameters. What we want to do is create a VC++ program that receives the input from another module over a UDP communication and sends the output back to this module over UDP.
Is it possible to use this simulink model in your suggested way as .m files or .mex files work?
Thank in advance for your reaction!
steven.romme@gmail.com
Steven Romme
 modified at 18:15 Wednesday 22nd March, 2006





Hi,
I sent an email. Sorry that I couldn't reply you soon because I'm in trip. Here is Nowrouz (New days) that are first days of Iranian year.
Best regards,
A. Riazi





Hi,
Thanks firstly for your article and the demos, I found it quite useful!
The problem that I am having currently is to do with calling my own functions in matlab, for example:
I have made a Mfile in matlab called "times_two.m" and inside:
function y = times_two(x)<br />
y = 2*x;
and now I have got your Matlab Engine code working inside my VC++ already, HOWEVER the problems occurs when I tried doing this:
//assume I have all the libraries included
int main(int argc, char* argv[])<br />
{<br />
CMatlabEng matlab; <br />
matlab.Open(NULL);<br />
matlab.EvalString("D = 100;");
<br />
matlab.EvalString("D = times_two(100);");<br />
mxArray myVal = matlab.GetVariable("D");<br />
myPrintingFunction(myVal);<br />
<br />
matlab.Close();<br />
<br />
return 0;<br />
}<br />
Now you would EXPECT the print out of the result will be 200, however it will just print 100 and I have tried many values on it and finally i have track down to the line:
matlab.EvalString("D = times_two(100);");
It seems as if it does not return the value to my variable "D", is it because Matlab Engine do not support userdefined functions or Mfiles? I am pretty sure that the function have been executed, just that it does not return the value...
(I am using Matlab 7 R14  the latest release)
Does anyone have a solution to this??
Thx in advance!!





Did you put your mfile in MATLAB path?
Best regards,
A. Riazi





I had the same problem. However, the matlab console has to be visible otherwise whether the output could be captured nor the result is calculated.





I have compiled and linked engdemo.c in MSVC++ 6.0. It gives 0 errors and 0 warnings. But when executed (please see the code below) only "Hi 1" is getting printed and it just waits. Nothing happens. engOpen(NULL) is not able to connect to MATLAB. Why this is happening.
printf("Hi 1\n");
if (!(ep = engOpen(NULL))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
printf("Hi 2\n");
Then i tried going to start>Run and typing C:\matlab7\bin\win32\matlab.exe /Automation. It opens MATLAB command window only. After that if i run the engdemo.c it works ans shows the desired result.
Is it not possible to start the MATLAB without doing the /Automation business.
Thanx in advance
Sunil





You used MATLAB 7 but the code that I provided was for MATLAB 6.5. Maybe the interface of MATLAB changed a bit.
The engOpen() runs the MATLAB in background. You can do this manually or in application (by using ShellExecute ).
Best regards,
A. Riazi





Dear Sir,
Thank you for the reply. But it didn't solve my problem. engOpen(NULL) should run the MATLAB in backgroud, but it is not happening to me. I am using MATLAB 7 and Win2K. Please see the code below.
int main()
{
Engine *ep;
if (!(ep = engOpen(NULL)))
{
fprintf(stderr, "\nCan't start MATLAB engine\n");
exit(0);
}
engEvalString(ep, "edit");
engClose(ep);
return 0;
}
This code gives 0 errors and 0 warnings using MSVC++6.0. But when run it doesn't open editor. Why is this so?
It will be gr8 if you can let me know what mistake am i doing, and why the above code is not running.





Your code is correct. As I said maybe the MATLAB interface changed a bit. You know that by using engOpen() you want to use MATLAB COM interface (Automation) to load the MATLAB IDE.
The code that I provide was for MATLAB 6.5 and you want to load MATLAB 7.
Best regards,
A. Riazi





Hello,
I had a BC++ application that invoked the matlab engine using engOpen. It worked perfectly with R13 version of Matlab. With R14, even though I included the new libs, I get the following strange behavior. It still opens the Matlab engine but closes it thereafter. If I use engOpenSingleUse then I get return code of 3. I am not sure what this code means.
Did someone else face this problem with R14 and if yes! how was it resolved.
Thanks,
Pwn





Hi there,
Firstly i would like to say that is a very good article.Congratulations for that.
Now i would come to my problem.I need to call my own function finddepth(w1,w2).m where w1 and w2 are [5][3] matrices , from C.I want to send the matrices w1 and w2 from c to matlab.The function finddepth should process these values and send the result which is an integer back to the C compiler where I would like to print the results.
I have placed the finddepth.m in the work directory of the matlab but i dont have any idea if its running or not as the C rogram doesnt give me any error even if i m putting a wrong name over there.How shall i run my own file?
How to get the result back from the Matlab to the C program and how to print the result?
If possible can you show me a program module with the above application?
I shall be obliged for your help
Stefan





First to find MATLAB runs your mfile or not, you can use OutputBuffer() function to redirect any messages from MATLAB to a user defined buffer.
Second, for getting result of your mfile (in this case a matrix or scalar), use GetVariable() function. This will give you a mxArray pointer. You can use helper functions to print it.
Best regards,
A. Riazi





sir ,
i have some trouble about this, but i already add Matlab headers directory to VStudio directory.when i start to link your demo program, it show up the error message:
"LINK : fatal error LNK1104: cannot open file "libeng.lib"
my develop environment is
Visual C++ 6.0
Matlab 6.5 realese 13
Any help you can give me would be great.
Thanks.





You must also add the library folder to VStudio directory.
Best regards,
A. Riazi





Oh~~
i already finish it!!thank you very much.
i copy all of these *.lib files to VStudio director(with source and header),is that right?
******************************************************
these three folders??
D:\MATLAB6P5\EXTERN\LIB
D:\MATLAB6P5\EXTERN\INCLUDE\CPP
D:\MATLAB6P5\EXTERN\INCLUDE
I already add these folder to VStudio director.
thanks for your answer!!
 modified at 7:25 Tuesday 10th January, 2006





There are library files for MSVC, Borland C++ Builder and WATCOM. You must add the MSVC library file to VStudio.
Best regards,
A. Riazi





How and where do we add the MSVC lib files?





Hello Mr. Riazi,
I read your article with interest.
I am using Compaq Visual Fortran6.6. I have Matlab6 installed in my computer with the operating system being Windows2000. Recently I also installed Matlab 7.1, so I have both Matlab6 and Matlab7.1. Previously I could easily execute this type of hybrid code:
program matplot
integer engOpen,engEvalString, engClose,ep
!DEC$ATTRIBUTES DLLIMPORT :: LIBENG
ep = engOpen('matlab ')
if (ep .eq. 0) then
write(6,*) 'Can''t start MATLAB engine'
stop
endif
call engEvalString(ep, 'cd c:\matplot')
call engEvalString(ep, 'plotmor');
end program matplot
I have included the lib libeng.lib in the resource area, the path being:
C:\Program Files\MATLAB71\extern\lib\win32\digital\df60\libeng.lib
Now I always get the message 'Can''t start MATLAB engine'
For libeng.lib I went back to Matlab6, but that does not work also. I am sure if I remove Matlab71 from the computer it will work again. But I do not like that. I like to keep both versions of Matlab and be able to invoke Matlab from my visual fortran routine.
Looking for a work around.
Thanks
Dilip





Dear all,
I have a problem with the MATLAB engine. I ask a MATLAB engine to evaluate a .m function. When the .m function is running I want to transfer matrix data to the MATLAB engine's workplace. This is because I receive data during certain events. The .m function can then read the new data and act
accordingly.
But unfortunately MATLAB does not work in this way. If an .m function is running, MATLAB does not put any new data in the workspace. I receive the matrix data only after the .m function has terminated.
Does anybody have a solution to this problem? I considered making an outofprocess COM server, so that I could call from inside my .m function to collect event data. This is a not so nice principle. Firstly, it is not event driven anymore. Secondly, I am writing a DLL, which calls my MATLAB engine. To write a outofprocess COM server in a DLL is a lot harder than writing it in an executable.
I hope somebody has some suggestions.
Kind regards,
Marcel Dijkstra





the weblink
http://www.mathworks.com/support/solutions/data/118CBI.html?118CBI
does help a bit.
But I want to do some simple plot in C/C++ using matlab 'plot' function.
saying changing the foo.m into test_plot.m
% test_plot.m
function y= test_plot(x)
x=1:10;
y=plot(x)
I can managed to compile and produce a test_plot.exe successfully. But upon execution of test_plot.exe in Command Prompt, it says:
ERROR: Function 'plot' requires the C/C++ Graphics Library.
EXITING.
I tried using a lower version of matlab 6.1, with Graphics Library, but it gives the same error.
I am reluctant to use Matlab 7, and compile, and create the MCR, because it is not suitable for me, and I just need to add in the plotting function into my existing C/C++ code. Dealing with MCR would make things more messy.
Or,
seem to me that another better option is to use the MATLAB Builder for COM, which I have not explored before.
any useful inputs is fully appreciated.
thanks.
Sincerely,
Thiam Huat





hi,
i tried but could not crack this problem.pls try to solve this.
i want a task to run until i press the "return" key.
for example send the data character out the com port continiously until i press "return" key.
pls mail me the way.
thk u
Ajo








General News Suggestion Question Bug Answer Joke Praise Rant Admin Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

