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);

52 Comments

  1. What an amazing guide! Can’t wait to use this when I travel to Amsterdam. This was very informative.

    • stridentgoggles

      May 29, 2023 at 8:04 pm

      Is your wish list filled of celebrity outfits you’ve always wished you could wear? Now is the moment to mark items off your list, since we provide the lowest pricing on everything you need. phrazle

  2. Is your wish-list full of your favorite superstar costumes that you always wanted to have in your wardrobe? It’s time to cross all of them, because we have got everything for you at the cheapest prices ever! Grab your favorites at hiltonsky.

  3. Downloading Iranian pop songs is one of the topics that are searched for a lot on the Internet. Today, pop or popular songs are among the most popular and popular types of music around the world. The popularity of rhythm and poetry is evident, both from singers and performers, as well as from listeners and music lovers in pop songs. This can also be the first and most important source of the general tendency towards this style of music among (https://bit.ly/3jSMSx2) the public.

    • This feature and the most legit is precious to see here. Still, there are also very interesting and the most informational Academic careers consumers available at your services named, Assignment Writers Cambridge, which is so perfect in delivering their best-qualified services all over the UK reasonably with great humbleness.

  4. incredibly helpful and simply explained, thanks so much!
    Ornaments

  5. Hey!
    incredibly helpful and simply explained, thanks so much!

  6. The jackets that we sell are replicas of the coats worn by top television celebrities because it is a growing trend to copy them when it comes to fashion. These celebrities have really become the trendsetters. This leisure was hitherto in reach of only the rich and the rest could only dream about it. But now these jackets are available for all people who want to buy them because of our affordable prices. So we welcome you to come and buy celebrity jackets of excellent quality and know more about us and our products! Leather Vest

  7. An obligation of appreciation is all together for sharing an especially amazing post. It was really helpful. Keep on sharing more substance. Leather Vest

  8. All of our escorts in Islamabad have accessible a large network of escorts and call girls at Islamabad.
    We give you top escorts at any given place. Escorts in Islamabad females provide their moment into their customers to receive their desires, and they’re exceptionally
    proficient women that are therefore much careful into some of their customers demand and possess professional approaches
    to create the finest and also understand just how to continue to keep things in well mannered way,
    thus have an exhaustive appearance on your Gallery on the perfect girl then call or text us to be in touch with.

  9. All of our escorts in Islamabad have accessible a large network of escorts and call girls at Islamabad.
    We give you top escorts at any given place. Escorts in Islamabad females provide their moment into their customers to receive their desires, and they’re exceptionally

  10. Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up

    captain america leather jacket

  11. 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.
    Thanks, dear for sharing your ideas. I really love your whole blog.

  12. The article I see the need and importance of the information it provides. We hope the article provides such good information in the future.
    https://crackcool.com/iobit-protected-folder-crack/

  13. Thanks for such an amazing content. https://www.homatz.co.uk/

  14. We will like to introduce our Firm as manufacturer and exporter of high quality Garments
    koszulowa kurtka

  15. chicago bulls jersey jordan 23 worldwide towards entire satisfaction of our valued customers.

  16. Website design company in Salem , >Website design company in Chennai , logo design nike air vapormax flyknit 3

  17. Thanks for your incredibly helpful and simply explained!

  18. Did you know? That concrete is the single most widely used building material in the world? Khoan cắt bê tông Đồng Nai

  19. Did you know? That concrete is the single most widely used building material in the world?

  20. Make your style stunning by wearing this Kate Upton Astros Jacket this jacket is made from high-quality material and you will never disappoint with the quality of this so don,t think anymore just click and shop now.

  21. Looking for a party hall in Hyderabad? Check out our list of the best party halls in Hyderabad, complete with photos, prices, and reviews!

  22. Onroadz Cabs is one of the most reliable and affordable taxi service providers in India. onroadzcabs.com Coimbatore taxi website offers our customers a wide range of taxi options for their daily commute, including hatchbacks, sedans, and SUVs.

  23. I am already done it and find that this post is really amazing.

  24. love the content of this blog and the positive you have. Thanks!
    B3 Men Shearling Aviator Bomber Leather Jackets

  25. I like this content and I love this blog Noelle Bill Hader Red Shearling Coat

  26. MATLAB C/C++ Compiler with Visual C++ is an amazing tool that makes it easy to compile and run C/C++ code from within MATLAB. If you’re looking for a reliable, effective way to manage your logistics, then you need our software. Contact us today to learn more!

  27. Thanks for sharing this amazing informative content it is really helpful I will definitely share it with my friends

  28. 3amoto Leather provides a hassle-free method to purchase on a budget. Our website offers a distinguished type of clothes that has been creatively designed for people like you! Every item on our store has passed a quality assurance test, ensuring that you have the greatest possible clothing. Our extensive inventory includes a wide range of casual and formal clothing. Our craftsmen’s extraordinary expertise profoundly finds those varieties.
    leather jacket studs

  29. As the world gets more contemporary, everyone wants to stay up with the latest trends. The primary goal of every fashion aficionado is to stay up with the current trends. Movies and television programs, like the gaming industry, exhibit its lovers’ fresh and fashionable attire.

    A jacket was designed for women who appreciate displaying their rebellious side. Women’s Blue Biker Jacket boasts magnificent and distinguishing features for a true biker style. This jacket’s aesthetics are really original and current, making it suitable attire for any outdoor activity.

  30. capybara clicker

    March 13, 2023 at 1:29 am

    Excited anticipation is a direct result of your sharing this information with us. A debt of gratitude is in order for your disclosure. Try your hand at our games if you’re feeling bored at work or school; they’ll be just the tonic you need. I appreciate it. capybara clicker

  31. I must say that it is very impressive post after visiting the post i thought i am in redemption island cast the island of knowledge.

  32. The Cyberpunk Jacket is a futuristic and edgy piece of clothing that has become increasingly popular in recent years. Inspired by the cyberpunk subculture and popularized by movies, TV shows, and video games, this type of jacket features unique design elements such as neon colors, leather, and metallic hardware. The Cyberpunk Jacket is often made from high-quality materials such as faux leather, PVC, or polyester, providing both durability and comfort. It is a versatile piece of clothing that can be styled in many ways, from casual outfits with jeans and boots to more formal looks with dresses or skirts. The Cyberpunk Jacket is popular among individuals who appreciate the unique and edgy style and want to make a statement with their fashion sense. It’s a must-have for anyone looking to stand out in a crowd and embrace a futuristic aesthetic. Overall, the Cyberpunk Jacket is a symbol of rebellion, innovation, and individuality, making it a popular choice among fashion-forward individuals who want to express their creativity and unique style.

  33. MATLAB is a powerful software that can help with numerical calculations and graphics, but it can be difficult to use if you’re not familiar with MATLAB’s C programming language. In this tutorial, we’ll show you how to use the MATLAB C compiler with Visual C so that you can create your own code andscripts. First, you’ll need to install the MATLAB C compiler and Visual C. Then, we’ll show you how to create a Basic Application project in VisualC and add a reference to the MATLAB C compiler inside the project. Once that’s done, we’ll show you how to compile and run your code using the Debugger tool in VisualC.

  34. MATLB is a powerful software that can help with numerical calculations and graphic, but it can be difficult to use of if you’re not familiar with MATLB’s C programming language.

  35. That was seems very great mcdvoice

  36. That was seems nic.

  37. That was seems nic. mcdvoice

  38. this is an informative post and it is very beneficial and knowledgeable. x trench run

  39. this is an informative post and it is very beneficial and knowledgeable.
    x trench run

  40. Candy Crush is a simple and sweet match 3 puzzle game that is easy to learn and play. Complete levels by swapping colored candies on the game board to match three or more candies of the same color. Use boosters wisely to pass those extra puzzles! Blast chocolates and collect sweets through thousands of levels, guaranteed to have more cravings!

  41. You have provided lots of useful information about various topics related to IT fields.”cyberpunk 2077 samurai jacket

  42. Great insights on social media marketing! I particularly enjoyed reading your article on and how it can boost brand visibility. It aligns perfectly with my recent blog post about

  43. Social Media Marketing Agency

    May 20, 2023 at 4:51 am

    Great insights onsocial media marketing ! I particularly enjoyed reading your article on and how it can boost brand visibility. It aligns perfectly with my recent blog post about

  44. I’m grateful that you published the really interesting post. I’m forward to read more of your writing. Visit my website to join our organisation! There are daily promos and academic support accessible!

  45. This information is stunning. I am really inspired by your post-writing style & how continuously you describe this topic. After reading your post, I feel very happy about it and I love learning more about this topic. Please keep upda

  46. This information is stunning. I am really inspired by your post-writing style & how continuously you describe this topic. After reading your post, I feel very happy about it and I love learning more about this topic. Please keep updating this excellent post.

  47. I like it. Thanks for sharing this fantastic post.

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑