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. The comprehensive and informative guides on sustainable event planning and eco-friendly event practices on your website make it a valuable resource for backlink inclusion among event management companies and event planning resources.Cyberpunk 2077 Samurai Jacket

  2. I have read your blog post and that is really informative as well. My friend recommended your blog and trust me through reading such amazing updates we able to change our perception as well. Keep writing such custom hat amazing stuff always. Star Trek Picard Field Jacket

  3. Thanks for sharing informative information keep sharing with us.

    • Event organisers and planning firms may benefit greatly from linking to your site for the wealth of information drift hunters you give on sustainable event planning and environmentally friendly event practises.

  4. Thanks for sharing such a valuable content.

  5. Gain insights into effective negotiation techniques and strategies for conflict resolution. Cyberpunk 2077 Green Leather Jacket

  6. Embark on a transformative journey fueled by our meticulously curated and thought-provoking content. Cyberpunk 2077 Jacket

  7. Immerse yourself in the deep well of wisdom offered by our meticulously investigated articles. Cyberpunk 2077 Jacket

  8. The article is a valuable addition to the field of knowledge. Kate Upton Jacket

  9. Jean-Luc Picard is known for his distinguished style, often wearing his Starfleet uniform or more casual attire. If a leather jacket were to be introduced in the upcoming season, it might symbolize a more adventurous or unconventional phase in his life. However, without specific information about the jacket’s design or significance in the story, it’s challenging to provide a detailed description.

  10. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking
    brown leather jacket mens

  11. Excellent article. Very interesting to read. I really love to read such a nice article.
    brown leather jacket mens

  12. The web page you have shared contains a lot of information. I have accumulated a lot of information.

  13. You really work great for this post. Thank you for sharing!Immigration Fraud Lawyer

  14. Thank you for sharing this insightful article! It provided me with a fresh perspective on the topic and expanded my understanding. Need Writing Help Visit now

  15. Thank you for sharing this insightful article! It provided me with a fresh perspective on the topic and expanded my understanding. Need Writing Help Visit now https://myassignmenthelp.com/

  16. I found this post very interesting and informative. Thank you for sharing your special thoughts with us. I definitely share this with my peeps.

  17. I found this very interesting and informative post. Thanks for sharing this with us.

  18. I value this blog post very interesting.

  19. As dedicated A4 Paper Manufacturers, we take pride in producing high-quality paper products that meet the diverse needs of businesses, offices, and individuals worldwide. Our commitment to excellence ensures that our A4 paper is not only reliable but also environmentally responsible.

  20. Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though.

  21. This guide seems to cover the steps necessary to integrate MATLAB functions into a C/C++ project using the MATLAB C/C++ Compiler with Visual Studio

  22. My greatest achievement was beating Run 3 in 20 mins whilst in a French lesson.

  23. Dubai’s interior fit-out companies stand as exemplars of sophistication and innovation, transforming spaces into captivating works of art. Renowned for their meticulous attention to detail and commitment to excellence, these firms redefine luxury and functionality, setting the standard for world-class interior design in the cosmopolitan city. With a fusion of creativity and precision, Dubai’s interior fit-out companies continue to shape the landscape of opulent living environments, reflecting the city’s modern and cosmopolitan character.

  24. This is a great inspiring article

  25. Nice article that taught me something. This post is the best one on this important subject fnaf

  26. Such a wonderful information blog post on this topic .nursing dissertation topics provides  at affordable cost in a wide range of subject areas for all grade levels, we are already trusted by thousands of students who struggle to write their academic papers and also by those students who simply want assignment Help to save their time and make life easy.

  27. It is important to note that this is a general overview, and the specific process may vary based on factors like location, house design, and project complexity. Hiring experienced professionals, including architects, contractors, and tradespeople, is crucial to xây nhà trọn gói ensure a successful construction process.

  28. Công ty xây dựng Phú Nguyễn nhận báo giá xây thô ưu đãi nhất. Bên cạnh đó chúng tôi hoặc động 24/7, luôn sẵn sàng phục vụ khách hàng khi có yêu cầu.

  29. Useful topic. IPSR is one of the world’s leading Red Hat Training and Certification partners with 40+ National and International awards, and produced the highest number of Red Hat professionals in the world. Visit us : red hat certification course

  30. Bảng giá xây nhà 2024 cần tìm hôm nay. Công ty xây dựng Phú Nguyễn chúng tôi luôn cập nhật giá hằng ngày giúp cho khách hàng lựa chọn giá tốt nhất có thể.

  31. Вполне оригинальная статья, я считаю . Когда-то в будущем тоже хочу вести несколько подобный блог. Сейчас некогда, другие заботы, связанные с полномасштабным российским вторжением.

  32. Visit our site to find more about wedding photographer Northern Virginia. We offer engagement and proposal photography in Va. BRIDALVENUS

  33. Loretta Johnston

    February 28, 2024 at 2:05 am

    Simply open VS Code/VS Code Insiders, open any folder, and create any file with the extension .c for the C file and drift hunters .cpp for the C++ file.

  34. I appreciate you sharing this information with me; I will undoubtedly put it to good use. If you are searching for another fantastic website that provides free entertainment options, you should check out fireboy and watergirl.

  35. Thanks for your post.
    Our team of experienced photographers will help you promote your business in the best way possible.

  36. Make heads turn with The Fall Guy Red Jacket, the ultimate fashion statement.

  37. It’s not love or anything, but I think I like you, too.

  38. word wipe aarp

    April 15, 2024 at 4:02 am

    Along with the information here word wipe aarp, I’ll also welcome you online. Some of my all-time favorites and most well-known games are on this very nice list of the games I’ve played. Something else. I think you’ll enjoy these games.

  39. Terabox APK offers users a convenient platform for storing and accessing their files securely in the cloud. With its intuitive interface and robust features, Terabox APK simplifies file management tasks, providing users with flexibility and peace of mind for their digital storage needs. For more information you can visit: https://teraboxmodapk.me/

  40. Thanks for sharing such great information, the post you published has some great information which is quite beneficial for me. I highly appreciate your work abilities. You can also Check this Cotton Jackets

  41. Publishing your research in a reputable anna university annexure 1 journals list is a significant achievement. Doctorate Writing can help you navigate the intricate process of identifying relevant journals in your field, understanding their specific submission guidelines, and crafting a compelling cover letter that highlights the significance of your research.

    https://doctoratewriting.com/anna-university-annexure-1-journals.html

  42. I appreciate you for sharing this valuable information.

  43. I’m the best Exam Help writer with over 10 years of experience in delivering top-notch, plagiarism-free academic assistance. Specializing in all subjects, I ensure quality and reliability for your exam needs. Contact me now for expert help and a free consultation at +44 7700 168833. Your success is my priority!

  44. Purwadi Sirait

    June 18, 2024 at 7:43 pm

    This post was incredibly insightful! Thanks for sharing your knowledge with us. Sultan88

  45. I really amazed to read this blog post. It is so unique and informative. I found very meaningful knowledge through this blog and I must say that this blog really helps us to design a circuit using these tips.

  46. Neobancos extranjeros

    June 27, 2024 at 1:39 am

    Excellent research and writing work. Congratulations from neobancos con IBAN extranjero

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑