1 / 23

MATLAB for C/C++ Programmers

MATLAB for C/C++ Programmers. Support your C/C++ development using MATLAB’s prebuilt graphics functions and trusted numerics. Agenda. Example C/C++ application Sending data to MATLAB for plotting and testing Adding MATLAB S/W modules into your application

cher
Download Presentation

MATLAB for C/C++ Programmers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB for C/C++ Programmers Support your C/C++ development using MATLAB’s prebuilt graphics functions and trusted numerics

  2. Agenda • Example C/C++ application • Sending data to MATLAB for plotting and testing • Adding MATLAB S/W modules into your application • Complete application development in MATLAB

  3. Example C/C++ Application

  4. Example C/C++ Application • Wireless Networking Simulation • w3.antd.nist.gov/wctg/bluetooth/btint.html

  5. C/C++ Code and Development • Code • Files • Classes • Development • Build and run • Debug • Difficult to understand data and operation of algorithms S/W (C_Application) Demonstration after

  6. Problems • Can’t easily visualize your data as plots, especially useful when developing and debugging • Difficult to verify your algorithm against a standard

  7. Solution: Send Data to MATLAB • High-level interpreted language and development environment • More than1000 built-in functions • Graphics and charting • Linear algebra, statistics, transforms, filtering • Can control from another application

  8. Sending Data to MATLABfor Plotting and Testing

  9. Calling MATLAB from C/C++ • Start MATLAB • matlab.exe /Automation • Optionally start desktop • In C/C++ code • Use MATLAB Engine library #include “engine.h” Engine *ep; ep = engOpen(NULL); engPutVariable(…); engGetVariable(…); engEvalString(…);

  10. Transferring Data to MATLAB // Data array in C double data_c[10] = {8,1,2,3,2,5,-1,7,8,3}; // Array to store data ready to transfer to MATLAB mxArray *data_ml; // Data array in MATLAB format data_ml = mxCreateDoubleMatrix(1,10,mxREAL); // Copy C array data into MATLAB array data memcpy((char *)mxGetPr(data_ml),(char *)data_c,10*sizeof(double)); // Transfer to MATLAB engPutVariable(ep,"data",data_ml); S/W Demonstration (Sending_Data) after

  11. Test Your C/C++ Algorithms • Reconstruct algorithms in MATLAB • Call test program to compare C result with M result engPutVariable(ep,“input”,input_ml); engPutVariable(ep,“output”,output_ml); engEvalString(ep,“testmyalg(input,output)");

  12. Example Algorithm Comparison • C++ Code algorithm Bits spread=addChips(diffOut[slice(i,1)]); Bits IEEE802_11b_Transmitter::addChips(const Bits& input) { Bits spreadOut(input.size()*Ns,false); for (int i=0;i<input.size();++i){ for(int j=0; j<11; ++j) { spreadOut[i*Ns+4*j]= m_chip[j]^input[i]; } } return spreadOut; } • M Code algorithm Tx_chips=reshape(Barker*Tx_symbols',[],1); Tx_samples(1:Samples_per_chip:end)=Tx_chips;

  13. Benefit of Sending Data to MATLAB • Easily visualize and understand your data • Verify your algorithm is correct, reducing risk of failure later

  14. Problems • No canned math, statistics, numerics and data analysis functions common in technical computing algorithms • You must write them yourself, which can be time consuming, or use other libraries

  15. Solution: MATLAB Module for Engineering or Mathematical Components • For heavy engineering or mathematical components of your application • Create a MATLAB module using the many built-in functions • Vector and matrix based • Application specific functions in toolboxes • Convert to a DLL or COM object with the MATLAB compiler • Distribute freely with your application

  16. Adding MATLAB Modules toYour C/C++ Application

  17. Design M code function foo.m Use MATLAB Compiler Converts MATLAB Code to standalone exe or library Create Foolib.dll Add include and library files to project See application note 27671 Build Component Example

  18. Calling from C S/W Demonstration after

  19. Benefits of Using a MATLAB Module • Leave MATLAB to the heavy math and engineering tasks what it is designed for • No need to spend time re-creating functions in C/C++ yourself that are already available in MATLAB • No need to test MATLAB’s trusted numerics

  20. Complete ApplicationDevelopment in MATLAB

  21. MATLAB Application Development • Build graphical user interface • Call C/C++ code • The MATLAB Compiler • Standalone option • Benefits • Faster development S/W Demonstration after

  22. Summary

  23. MATLAB Can Support Your C/C++ Development • Send data to MATLAB for plotting and testing • Easily visualize and understand your data • Verify your algorithm is correct • Add MATLAB S/W modules into your application • Leave MATLAB to the heavy math and engineering • No need to spend time re-creating functions in C/C++ • Develop complete applications in MATLAB • Faster development technical computing problems

More Related