> doc sin % spawns a new document window with details on sin > quit % quits MATLAB (also exit) > lookfor cosine % if you don't know the function name acos - Inverse cosine, result in radians.Īcosd - Inverse cosine, result in degrees. > help sin % if you know function name but not it's usage SIN Sine of argument in radians. > help elfun % lists elementary math functions Elementary math functions. Matlab/elfun - Elementary math functions. Matlab/randfun - Random matrices and random streams. Matlab/elmat - Elementary matrices and matrix manipulation. Matlab/lang - Programming language constructs. Matlab/ops - Operators and special characters. Matlab/general - General purpose commands. > help % lists available packages/toolboxes.
#MATLAB A VS MATLAB B CODE#
When you are ready to start writing your own code, you may want to take advantage of this to document your own code wherever appropriate to make clear your intentions for future reference. Throughout this tutorial, we will use this ( %) inline comment feature to explain the meaning or purposes of the commands. > version % this tells you the running MATLAB version ans = Output, if any, appears after the the command is entered. Note that all typed characters to the right of the % symbol are treated as explanations or documentation for the line. The example below demonstrates the use of a MATLAB utility function called version to query the current version of MATLAB you are using on this computer. Start using MATLAB by entering MATLAB commands at >. In either case, a MATLAB command window appears, along with a > prompt. To start MATLAB in Linux: enter matlab at the system prompt of a X-Forwarding window scc1% matlab &.To start MATLAB in Windows: double click the desktop MATLAB icon.Or use logical indexing with the complement of the segmentation result to compute the histogram of the background pixels. Whos foreground_pixels Name Size Bytes Class Attributesįinally, compute the histogram of the foreground pixels. Now use the segmentation result as a logical index into the original image to extract the foreground pixel values. Here's a segmentation result (computed and saved earlier), represented as a binary image: url = '' Here's our original image: I = imread( 'rice.png') Given a gray-scale image and a binary segmentation, compute the histogram of just the foreground pixels in the image.
#MATLAB A VS MATLAB B HOW TO#
Here's an example showing how to use logical indexing to compute the histogram of a subset of image pixels.
This convention, together with logical indexing, makes it very convenient and expressive to use binary images as pixel masksįor extracting or operating on sets of pixels. For example, when you readĪ 1-bit image file using imread, it returns a logical matrix: Whos nan_locations Name Size Bytes Class Attributesįunctions in the Image Processing Toolbox, as well as the MATLAB functions imread and imwrite, follow the convention that logical matrices are treated as binary (black and white) images. Now we know enough to break down the B(isnan(B)) example to see how it works. The logical indexing expression C(D) extracts all the values of C corresponding to nonzero values of D and returns them as a column vector. You can see from the output of whos that the class of the variable D is logical. Relational operators, such as = or >, produce logical matrices. "Logical" is one of the builtin types, or classes, of MATLAB matrices.
If C and D are matrices, then C(D) is a logical indexing expression if C and D are the same size, and D is a logical matrix. Let's talk about the basic rules of logical indexing, and then we'll reexamine the expression B(isnan(B)).
Logical indexing is a compact and expressive notation that's very useful for many image processing operations. Replace the NaNs with zeros: B(isnan(B)) = 0 This is generally followed 4.8 minutes later with this reply from one of the newsgroup regulars: B(isnan(B)) = 0 How do I replace all the NaNs in my matrix B with 0s? When an indexing expression appears on the left-hand side of the equals sign, it's assignment: A(5,5) = 100Ībout every 13.6 days, someone asks this question on : You can extract more than one row and column at the same time: A = magic(5)Ī(2,3) extracts the 2nd row, 3rd column of the matrix A. Later I'll cover linear indexing, and then a technique I like to call neighbor indexing.Įvery MATLAB user is familiar with ordinary matrix indexing notation.
#MATLAB A VS MATLAB B SERIES#
This is the first post in a short series on index techniques that are particularly useful for image processing in MATLAB.