Programming and Developing Algorithms with MATLAB
Write programs and develop algorithms using the high-level language and development tools in MATLAB®.
MATLAB provides a high-level language and development tools that let you quickly write MATLAB programs, develop and analyze algorithms, and build applications. MATLAB is a matrix-based language. It natively supports vector and matrix operations that are fundamental to engineering and scientific problems.
For example, you can operate on all of the elements in a matrix with a single command without having to write a for loop. As a result, one line of MATLAB code often replaces several lines of C or C++ code.
MATLAB provides features of traditional programming languages, including flow control, such as while and for loops; error handling, such as try catch blocks which allow us to execute statements and catch the resulting errors; and object-oriented programming. Here you can see a class defined in MATLAB together with its properties and methods.
The MATLAB environment is well suited for algorithm design and exploration. In this example, we're developing an algorithm to identify the center of a hurricane. Because MATLAB is a high-level language there's no need to perform low-level administrative tasks, such as declaring variables, specifying data types, and allocating memory.
Using the Command window, you can execute commands one at a time, providing you with immediate results. This interactive approach makes it easy to quickly explore multiple options and iterate to an optimal solution.
You can create a MATLAB script or function from the commands you've already entered. This makes it easy to reuse and automate your work. MATLAB provides built-in algorithms for signal processing and communications, image and video processing, control systems, and many other domains. Here, we're using a function from Image Processing Toolbox™ to identify and measure properties of connected regions in an image.
MATLAB provides development tools that help you implement your algorithms efficiently and optimize their performance. The MATLAB editor is where you create and edit programs. The editor provides debugging features. You can set breakpoints, examine variable values, and step through individual lines of code.
The Code Analyzer automatically checks code in the MATLAB editor for problems. When you hover over underlined code fragments, the Code Analyzer provides an explanation of the problem and suggestions on how to fix it. The MATLAB Profiler measures the overall performance of MATLAB programs and identifies areas of code to focus on for improvement. The Profile Summary report gives information about the functions called, including the time each function took to run, how many times each function was called, and which lines of code took the most processing time.
You can integrate your MATLAB applications with those written in other languages, such as C, C++, Java, and .NET. Here we have C code for a 2D Gaussian function. This code was compiled into a MEX function, or MATLAB executable, and can be called directly from within MATLAB. Similarly, you can call MATLAB code directly from your C, C++, or FORTRAN applications.
MATLAB uses processor-optimized libraries for fast execution of matrix and vector computations. Many linear algebra and numerical functions are multi-threaded, allowing them to run faster on multicore computers. You can use the high-level constructs found in the parallel computing products to parallelize your applications with only minor code changes. This allows you to take further advantage of multicore desktops and other resources, such as GPUs and clusters. With MATLAB you can easily transform your ideas into algorithms and complex applications.
For more information about MATLAB, see the product page or watch one of the other videos.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.