Jeremy W. Langston

Personal Website

Steps for using MATLAB C/C++ Compiler with Visual C++

In Visual Studio:

0)  Create an empty C/C++ project.

 
In MATLAB:

1)  Write the m-file with one function to expose to C/C++.

        function [xp, length] = ExpandArray( x, interval)
        xp = 0:interval:x(length(x));
        length = length(xp);

2)  Create a deployment project (File->New->Deployment Project).

3)  Add m-file to “Exported functions” in deployment project.

4)  Change the settings of the deployment project to put the output directory output to the directory of the source files for the C/C++ project.  Set the Library Name (e.g. “Functions”).
In Visual Studio:

5)  Right-click on the project->Properties.

5a) Under C/C++->General, add the directory of the MATLAB header files to “Additional Include Directories”:

      "C:\Program Files\MATLAB\R2007a\extern\include"

5b) Under Linker->Input, add the directory of the MATLAB libraries and the location of your newly created MATLAB library to “Additional Dependencies”:

      "C:\Program Files\MATLAB\R2007a\extern\lib\win32\microsoft\mclmcrrt.lib"
      "C:\...\Functions.lib", where "..." is the path of the output directory set in step 4

6)  Add the created header file to your project and include it in your C/C++ code where appropriate.

7)  In your C/C++ code, initialize the MATLAB component:

      bool ret = FunctionsInitialize();
      if (!ret){
        std::cout << "Error initializing MATLAB Component Runtime\n";
        system("PAUSE");
        return 0;
      }

8)  Create the input variables to the MATLAB function:

      double x[4] = {1,2,3,4};
      mwArray mwX(1,4,mxDOUBLE_CLASS);
      mwX.SetData(x,4);
      mwArray mwInterval((double) 0.1);
      int nargout = 2; // this says you will be using 2 outputs, xp and length

9)  Create the output variables from the MATLAB function:

      mwArray mwXP;
      mwArray mwLength;

10) Call your function:

      ExpandArray(nargout, mwXP, mwLength, mwX, mwInterval);

11) Get the data out of the mwArrays:

      int length;
      mwLength.GetData(&length, 1);
      double *xp = new double[length];
      mwXP.GetData(xp, length);

12) Terminate the use of the MATLAB component:

      FunctionsTerminate();

 
Notes:

If you only want to return one variable from your MATLAB function, set
nargout to 1 and the return variable will be as such:
  int returnVariable = MyFunction(nargout, inputVariable);

51 Comments

  1. Dear Jeremy,

    The line

    bool ret = FunctionsInitialize();

    Returns undeclared identifier for FunctionsInitialize.

    I assume you use Fuctions as this was the name for the matlab function.

    • Here, I take much information because I am new in web designing and development and now my profession is Mens Brown Leather Jacket designing and i always search these type of blog because I want to learn web development and designing

  2. Matlab presents library capabilities for a number of critical operations, and plenty of additional duties can be achieved through writing m-files from scratch. However, there are certain responsibilities that cannot be finished effectively the usage of the sources to be had inside Matlab itself.

  3. I did not know the basic implementation of the c++ and how it is used with the compiler along with visual c. The post helped me a lot and I started to learn that as well.

    https://itunessupport.org/blog/fix-itunes-error-9/.

  4. Matlab will only do numerical math for you and is pretty restrictive in the kinds of data structures it handles natively.

  5. Matlab and Mathematica are very different. It is not simply a matter of translation.

  6. Do I need to compile the system that it is, I can connect to Matlab. In the first place, the question, which is the 64-bit Matlab, he has no right to the compiler, so as not to be installed by means of the instructions of the SDK 7.1. After installation.

  7. Very wonderful experience.

  8. Matlab gives library capacities to various significant activities, and numerous extra assignments might be practiced Professional Dissertation Writers UK by composing m-documents without any preparation. However, there are sure undertakings that can’t be cultivated proficiently utilizing the assets accessible inside Matlab itself.

  9. I didn’t have the foggiest idea about the essential execution of the c++ and how it is utilized with the compiler alongside visual c. The post helped me a great deal and I began to discover that too. More information Visit as: https://uaewebsitedevelopment.com/

  10. Informative article for knowledge. However, we are one of the best Dissertation editing services that will help and guide you in every steps plus give solution to related topic or any other feel free to visit us any time we are serving 24/7.

  11. Matlab and Mathematica are very different. It is not simply a matter of translation.

  12. Waow Such A Great Expericence ..but Matlab and Mathematica are very different. It is not simply a matter of translation.

  13. Well, I don’t have much idea about it and i think Matlab is only doing numerical maths so it might be very restrictive in the data structure. I think the experts might give a good idea or suggestion about it.

  14. well, it’s a very informative article and I think experts can give good comments about this article and as far as I concerned Matlab is a numerical computing programming language made for mathematics work.

  15. When you start run Norton Removal Tool on Windows or MAC, it uninstalls the currently installed Norton setup and restarts your computer. After that, your computer restarts, this tool automatically install the new version of Norton setup. For more information, visit https://w-wnorton.com/setup/.

  16. important information is very useful to me. when you are using these platforms online there is a chance of insecurity like cybercrime and harmful virus-like malware spyware etc be secure with McAfee. it provides the best protection.

  17. cám ơn bạn vì những chia sẻ trên, bận thật tốt

  18. these compilers are also used in Roblox to create the games with different graphics and programming languages, these are the best supporting compilers.

  19. i have invented many compiler for personal use.

  20. I am a student of fashion designing and doing work athttps://medium.com/@USAJacket/cyberpunk-2077-jacket-review-386d6257be35 but I want to learn C++ i don’t know extra about this topic.

  21. Quickbooks is accounting software which comes with a lot of many latest and cool feature. if you are using QuickBooks and face any kind of technical problem then you can use QuickBooks technical support phone number.

  22. We not only provide Online Nursing Writing Services for our clients but help them understand Nursing Paper Writing Services procedures so that they can gain award winning Nursing Research Paper Writing Services knowledge.

    https://www.meldaresearch.com/nursing-writing-services-2/

  23. We not only provide Online Nursing Writing Services for our clients but help them understand Nursing Paper Writing Services procedures so that they can gain award winning Nursing Research Paper Writing Services knowledge.
    https://www.meldaresearch.com/nursing-writing-services-2/

  24. Thanks For sharing this Superb article.I use this Article to show my assignment in college.it is useful For me Great Work.

  25. Really very useful and Informative information are provided here. Thank you so much for writing keep up like this.

    https://thetechtrending.com/
    https://thetechtrending.com/best-alternatives-to-pubfilm-online-in-2020/

  26. I will in all likelihood association with this! You have also issued me inconceivable grub for the further examinations.

  27. Thanks for updating about new updates about FPSC Jobs

    I Appreciate your Skills Because Your Content is Awesome

    I will share these Awesome content to my official blog

    Thanks

    FPSC

  28. Thanks for updating about new updates

    I Appreciate your Skills Because Your Content is Awesome

    I will share these Awesome content to my official blog

    Thanks

    FPSC

  29. Online movies in high quality
    123Movies is a modern portal for viewing both obsolete and new films with high resolution. Especially for users of our resource, moderators for several years published films of various categories and years of release. The resource team daily adds new cinema, so that each user can be the first to watch movies online in HD quality.

    Here you will find for every taste from comedies to thrillers, from melodramas to horrors. If you can’t decide what you want to watch today, take a look at the ranking of the top best films of 2019 on the movie search. When compiling this rating, the site is guided not only by the opinion of experts, but also the opinion of movie lovers 2019-2020 at 123movies, which is also important, as their views often do not coincide. This resource has taken care of lovers of series. Now there is no need every day at a certain time to sit in front of the TV to watch the next episode of your favorite series, which is so often interrupted by advertising that you sometimes forget what was discussed. From now on, you can review your favorite TV shows for whole seasons or choose only new series for free.

    If you are gathered in the warm company of your friends or relatives, as well as close people, then you can have a great time watching a high-quality movie, film, series without leaving your home and without leaving your comfort zone, you just need to get comfortable, make a plate of delicious pop Korna and enjoy good quality pictures and great sound. Join our film club.net, whether you are a film enthusiast or a connoisseur of TV shows, we will find everything that you are looking for absolutely free, you will only share it with your friends, and we will watch all the new things together, without going anywhere and without paying for anything. Click on play and your immersion in another reality begins right now ….

  30. Get 100% Anonymous offshore hosting from WebCare360™ who standout amongst the most experienced dmca ignored hosting providers in the industry.

  31. Thanks for sharing this awesome blog.

  32. I really love your blogs.

  33. Nice and awesome post! thanks for sharing this valuable and interesting information with us. keep posting.

  34. Thanks for the advice! Only starting to code and this is really helpful

  35. This is the first time that I visit here. I found so many exciting matters in this particular blog, One thing I would like to request you that pls keep posting such type of informative blog.

  36. I appreciate this blog your blog is vert help full for me i really enjoyed this stuff dude.

  37. Follow the latest trends Project Power Jamie Foxx Jacket. Buy it and enjoy flat 80% off on all items.

  38. The article I see the need and importance of the information it provides. We hope the article provides such good information in the future.

  39. Very informative blog!

  40. We are the Best PhD assistance in india and we highly committed towards our customer gratification and Finishing your PhD on your time. We give best PhD guidance, PhD help, PhD Consultancy, PhD services in india
    website: http://higssoftware.com/phd-research-paper-writing-services.php

  41. Offshore Hosting with 100% DMCA ignored Hosting, Offshore Dedicated Server, Offshore VPS Hosting.

  42. Really explain everything in detail, the article is very interesting and effective. thank you!

  43. I did not know the basic implementation of the c++ and how it is used with the compiler along with visual c. The post helped me a lot and I started to learn that as well. Top Gun Jacket

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑